feat: add AsyncContext/Disposable support#3052
Merged
Skn0tt merged 1 commit intomicrosoft:mainfrom Apr 29, 2026
Merged
Conversation
Adds support for the Disposable return type that 12 driver methods now
return as of 1.59.1, so users can use them as context managers:
async with await page.route("**/*", handler):
...
# handler is automatically unrouted on exit
Affected methods (Page & BrowserContext): add_init_script,
expose_binding, expose_function, route. Plus Tracing.group and
Screencast.{start,show_overlay,show_actions}.
Two flavors:
- Disposable(ChannelOwner) wraps a driver-side Disposable channel
(used where the protocol returns one, e.g. addInitScript).
- DisposableStub is a Python-side wrapper that calls a dispose lambda
on exit (used for client-side pairings like route/unroute and
tracing.group/group_end).
Codegen rewrites both classes to AsyncContextManager/SyncContextManager
in the generated public API so consumers see standard Python types.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dgozman
approved these changes
Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds support for the
Disposablereturn type that 12 driver methods now return as of 1.59.1, so they can be used as context managers:Affected methods (
Page&BrowserContext):add_init_script,expose_binding,expose_function,route. PlusTracing.groupandScreencast.{start,show_overlay,show_actions}.Two flavors:
Disposable(ChannelOwner)wraps a driver-sideDisposablechannel (used where the protocol returns one, e.g.addInitScript,exposeBinding).DisposableStubis a Python-side wrapper that calls a dispose lambda on exit (used for client-side pairings likeroute/unroute,tracing.group/group_end,screencast.start/stop).Codegen rewrites both classes to
AsyncContextManager/SyncContextManagerin the generated public API so consumers see standard Python types.Picks up the bits that were missed in #3050 — these were originally part of #3044.