Skip to content

feat: add AsyncContext/Disposable support#3052

Merged
Skn0tt merged 1 commit intomicrosoft:mainfrom
Skn0tt:feat/disposable-async-context
Apr 29, 2026
Merged

feat: add AsyncContext/Disposable support#3052
Skn0tt merged 1 commit intomicrosoft:mainfrom
Skn0tt:feat/disposable-async-context

Conversation

@Skn0tt
Copy link
Copy Markdown
Member

@Skn0tt Skn0tt commented Apr 29, 2026

Adds support for the Disposable return type that 12 driver methods now return as of 1.59.1, so they can be used 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, exposeBinding).
  • DisposableStub is a Python-side wrapper that calls a dispose lambda on exit (used for client-side pairings like route/unroute, tracing.group/group_end, screencast.start/stop).

Codegen rewrites both classes to AsyncContextManager/SyncContextManager in 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.

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>
@Skn0tt Skn0tt requested a review from dgozman April 29, 2026 08:26
@Skn0tt Skn0tt merged commit d9a922d into microsoft:main Apr 29, 2026
29 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants