← Back to Debugger domain
Debugger.setScriptSource
Edits JavaScript source live.
In general, functions that are currently on the stack can not be edited with
a single exception: If the edited function is the top-most stack frame and
that is the only activation of that function on the stack. In this case
the live edit will be successful and a `Debugger.restartFrame` for the
top-most function is automatically triggered.
Domain: Debugger
stable
Parameters
| Name | Type | Description |
scriptId | Runtime.ScriptId | Id of the script to edit. |
scriptSource | string | New content of the script. |
dryRun (optional) | boolean | If true the change will not actually be applied. Dry run may be used to get result
description without actually modifying the code. |
allowTopFrameEditing (optional) | boolean | If true, then `scriptSource` is allowed to change the function on top of the stack
as long as the top-most stack frame is the only activation of that function. |
Returns
| Name | Type | Description |
callFrames | array | New stack trace in case editing has happened while VM was stopped. |
stackChanged | boolean | Whether current call stack was modified after applying the changes. |
asyncStackTrace | Runtime.StackTrace | Async stack trace, if any. |
asyncStackTraceId | Runtime.StackTraceId | Async stack trace, if any. |
status | string | Whether the operation was successful or not. Only `Ok` denotes a
successful live edit while the other enum variants denote why
the live edit failed. |
exceptionDetails | Runtime.ExceptionDetails | Exception details if any. Only present when `status` is `CompileError`. |
Example Request
{
"id": 1,
"method": "Debugger.setScriptSource",
"params": {
"scriptId": "1",
"scriptSource": "scriptSource-value"
}
}
Example Response
{
"id": 1,
"result": {
"callFrames": [],
"stackChanged": true,
"asyncStackTrace": "asyncStackTrace-value",
"asyncStackTraceId": "asyncStackTraceId-value",
"status": "status-value",
"exceptionDetails": "exceptionDetails-value"
}
}
Usage in Node.js
const result = await send('Debugger.setScriptSource', {"scriptId": "1", "scriptSource": "scriptSource-value"});
console.log(result);
// {"callFrames": [], "stackChanged": true, "asyncStackTrace": "asyncStackTrace-value", "asyncStackTraceId": "asyncStackTraceId-value", "status": "status-value", "exceptionDetails": "exceptionDetails-value"}