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>
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:
Affected methods (Page & BrowserContext): add_init_script, expose_binding, expose_function, route. Plus Tracing.group and Screencast.{start,show_overlay,show_actions}.
Two flavors:
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.