feat(page): support a callback in addInitScript#41861
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
||
| Optional argument to pass to [`param: script`] (only supported when passing a function). | ||
|
|
||
| ### param: BrowserContext.addInitScript.callback |
There was a problem hiding this comment.
Can this be consistent with evaluate where we support function values in arguments?
|
|
||
| Optional argument to pass to [`param: script`] (only supported when passing a function). | ||
|
|
||
| ### param: Page.addInitScript.callback |
any function in the `arg` for `page.addInitScript`/`browserContext.addInitScript` is now exposed as a callback the page can call, just like `evaluate(fn, arg, { exposeFunctions })` already does
the `arg` is serialized with the evaluate call argument serializer and rebuilt in the page on every navigation through a new `parseArgument` on the bindings controller
as a result, any callbacks survive navigations and reach all current/future pages
disposing the returned `Disposable` removes every callback binding
2646731 to
cb06032
Compare
Test results for "MCP"3 failed 7757 passed, 1249 skipped Merge workflow run. |
Test results for "tests 1"7 flaky50050 passed, 1188 skipped Merge workflow run. |
|
Hi, I'm the Playwright bot and I took a look at the failing CI on the latest run. 🟡 PR looks clear — two confirmed flakes, one msedge failure I can't fully proveThe two MCP failures I can trace history for are established flakes on unrelated PRs and DetailsThis PR only adds an Pre-existing flake / infra
Uncertain
Triaged by the Playwright bot Triaged by the Playwright bot - agent run |
|
this is handled by #41921 |
add an optional
callbacktopage.addInitScriptandbrowserContext.addInitScript(js only) so the injected script can pass data back to the runnera function script receives the callback as an argument (after
arg, or as its only argument whenargis omitted), and a string or file script can call it ascallbackthe in-page callback returns a
Promiseresolving to whatevercallbackreturns, runs on every navigation and in child frames, and for abrowserContextcovers all current and future pagesthe returned
Disposableremoves the init script, the binding, and the client binding entrythe client composes the init script source and registers
callbackthrough the existing evaluate binding machinery