addScriptToEvaluateOnNewDocument method

Future<ScriptIdentifier> addScriptToEvaluateOnNewDocument(
  1. String source, {
  2. String? worldName,
  3. bool? includeCommandLineAPI,
  4. bool? runImmediately,
})

Evaluates given script in every frame upon creation (before loading frame's scripts). worldName If 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 Specifies whether command line API should be available to the script, defaults to false. runImmediately If true, runs the script immediately on existing execution contexts or worlds. Default: false. Returns: Identifier of the added script.

Implementation

Future<ScriptIdentifier> addScriptToEvaluateOnNewDocument(String source,
    {String? worldName,
    bool? includeCommandLineAPI,
    bool? runImmediately}) async {
  var result = await _client.send('Page.addScriptToEvaluateOnNewDocument', {
    'source': source,
    if (worldName != null) 'worldName': worldName,
    if (includeCommandLineAPI != null)
      'includeCommandLineAPI': includeCommandLineAPI,
    if (runImmediately != null) 'runImmediately': runImmediately,
  });
  return ScriptIdentifier.fromJson(result['identifier'] as String);
}