← Back to Runtime domain

Runtime.compileScript

Compiles expression.

Domain: Runtime stable

Parameters

NameTypeDescription
expressionstringExpression to compile.
sourceURLstringSource url to be set for the script.
persistScriptbooleanSpecifies whether the compiled script should be persisted.
executionContextId (optional)ExecutionContextIdSpecifies in which execution context to perform script run. If the parameter is omitted the evaluation will be performed in the context of the inspected page.

Returns

NameTypeDescription
scriptIdScriptIdId of the script.
exceptionDetailsExceptionDetailsException details.

Example Request

{
  "id": 1,
  "method": "Runtime.compileScript",
  "params": {
    "expression": "document.title",
    "sourceURL": "sourceURL-value",
    "persistScript": true
  }
}

Example Response

{
  "id": 1,
  "result": {
    "scriptId": "scriptId-value",
    "exceptionDetails": "exceptionDetails-value"
  }
}

Usage in Node.js

const result = await send('Runtime.compileScript', {"expression": "document.title", "sourceURL": "sourceURL-value", "persistScript": true});
console.log(result);
// {"scriptId": "scriptId-value", "exceptionDetails": "exceptionDetails-value"}