GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add AsyncContext/Disposable support by Skn0tt · Pull Request #3052 · microsoft/playwright-python

Conversation

@Skn0tt

@Skn0tt Simon Knott (Skn0tt) commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Skn0tt
feat: add AsyncContext/Disposable support
7de5de2
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 <[email protected]>
@Skn0tt
Simon Knott (Skn0tt) requested a review from Dmitry Gozman (dgozman) April 29, 2026 08:26
dgozman
Dmitry Gozman (dgozman) approved these changes Apr 29, 2026
View reviewed changes
@Skn0tt
Simon Knott (Skn0tt) merged commit d9a922d into microsoft:main Apr 29, 2026
29 of 38 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@Skn0tt Simon Knott (Skn0tt) mentioned this pull request Apr 30, 2026
[Feature]Route&unroute can be made into contextmanagement #1800
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dgozman Dmitry Gozman (dgozman) dgozman approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Skn0tt @dgozman
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.