Skip to content

Implement Page.addScriptToEvaluateOnNewDocument CDP handler#57248

Closed
GijsWeterings wants to merge 1 commit into
react:mainfrom
GijsWeterings:export-D107084044
Closed

Implement Page.addScriptToEvaluateOnNewDocument CDP handler#57248
GijsWeterings wants to merge 1 commit into
react:mainfrom
GijsWeterings:export-D107084044

Conversation

@GijsWeterings

Copy link
Copy Markdown
Contributor

Summary:
Implement the CDP Page.addScriptToEvaluateOnNewDocument and Page.removeScriptToEvaluateOnNewDocument methods in the modern JS inspector (jsinspector-modern). Page.addScriptToEvaluateOnNewDocument registers a JavaScript snippet that is evaluated in every new JS runtime created for the Host (for example, after a reload), before the application's main bundle runs, matching the standard Chrome DevTools Protocol semantics. This is useful for debugger frontends and tooling that need to install instrumentation ahead of application code.

The registered scripts are stored as session state (alongside Runtime.addBinding subscriptions in SessionState) and replayed onto each new runtime by RuntimeAgent via the runtime executor, so they run before any user code and survive reloads. Per CDP semantics the script does not run in the runtime that is current when it is registered; the client triggers Page.reload to apply it. HostAgent handles both methods, returning the generated script identifier from add and removing by identifier on remove.

Changelog:
[General][Added] - Implement the Page.addScriptToEvaluateOnNewDocument and Page.removeScriptToEvaluateOnNewDocument CDP methods in the modern inspector

Reviewed By: hoxyq

Differential Revision: D107084044

Summary:
Implement the CDP `Page.addScriptToEvaluateOnNewDocument` and `Page.removeScriptToEvaluateOnNewDocument` methods in the modern JS inspector (`jsinspector-modern`). `Page.addScriptToEvaluateOnNewDocument` registers a JavaScript snippet that is evaluated in every new JS runtime created for the Host (for example, after a reload), before the application's main bundle runs, matching the standard Chrome DevTools Protocol semantics. This is useful for debugger frontends and tooling that need to install instrumentation ahead of application code.

The registered scripts are stored as session state (alongside `Runtime.addBinding` subscriptions in `SessionState`) and replayed onto each new runtime by `RuntimeAgent` via the runtime executor, so they run before any user code and survive reloads. Per CDP semantics the script does not run in the runtime that is current when it is registered; the client triggers `Page.reload` to apply it. `HostAgent` handles both methods, returning the generated script `identifier` from add and removing by `identifier` on remove.

Changelog:
[General][Added] - Implement the `Page.addScriptToEvaluateOnNewDocument` and `Page.removeScriptToEvaluateOnNewDocument` CDP methods in the modern inspector

Reviewed By: hoxyq

Differential Revision: D107084044
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 17, 2026
@meta-codesync

meta-codesync Bot commented Jun 17, 2026

Copy link
Copy Markdown

@GijsWeterings has exported this pull request. If you are a Meta employee, you can view the originating Diff in D107084044.

@meta-codesync meta-codesync Bot closed this in bc20ec8 Jun 17, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Jun 17, 2026
@meta-codesync

meta-codesync Bot commented Jun 17, 2026

Copy link
Copy Markdown

This pull request has been merged in bc20ec8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant