← Back to Page domain

Page.addScriptToEvaluateOnNewDocument

Evaluates given script in every frame upon creation (before loading frame's scripts).

Domain: Page stable

Parameters

NameTypeDescription
sourcestring
worldName (optional)stringIf specified, creates an isolated world with the given name and evaluates given script in it. This world name will be used as the ExecutionContextDescription::name when the corresponding event is emitted.
includeCommandLineAPI (optional)booleanSpecifies whether command line API should be available to the script, defaults to false.
runImmediately (optional)booleanIf true, runs the script immediately on existing execution contexts or worlds. Default: false.

Returns

NameTypeDescription
identifierScriptIdentifierIdentifier of the added script.

Example Request

{
  "id": 1,
  "method": "Page.addScriptToEvaluateOnNewDocument",
  "params": {
    "source": "source-value"
  }
}

Example Response

{
  "id": 1,
  "result": {
    "identifier": "identifier-value"
  }
}

Usage in Node.js

const result = await send('Page.addScriptToEvaluateOnNewDocument', {"source": "source-value"});
console.log(result);
// {"identifier": "identifier-value"}