add_init_script
Inject JavaScript into every tab at the start of each page load, before page scripts run, to record timings/DOM changes or stub APIs early; returns an ID for removal.
Instructions
Run JavaScript at the start of every page load in every tab of the session, before any of the page's own scripts, until removed or the session closes. Use it to record timings or DOM changes from the very first moment of a load (a MutationObserver, PerformanceObserver or console hook writing to a window global you read later with evaluate), or to stub an API before the page uses it. Takes effect from each tab's next navigation, not the page already loaded. It runs in the page's main world, so the page can see what it defines. Returns an id for remove_init_script. Needs the listener role.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | The JavaScript to run, as a script body (not a function). | |
| sessionId | Yes | The id returned by open_browser_session. Errors if no open session has it. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Pass to remove_init_script. | |
| network | No | Network throttling; null means none. | |
| initScripts | Yes | ||
| cpuThrottlingRate | Yes | CPU slowdown factor; 1 means none. |