← Back to Runtime domain
Runtime.compileScript
Compiles expression.
Domain: Runtime
stable
Parameters
| Name | Type | Description |
expression | string | Expression to compile. |
sourceURL | string | Source url to be set for the script. |
persistScript | boolean | Specifies whether the compiled script should be persisted. |
executionContextId (optional) | ExecutionContextId | Specifies 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
| Name | Type | Description |
scriptId | ScriptId | Id of the script. |
exceptionDetails | ExceptionDetails | Exception 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"}