← 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

NameTypeDescription
scriptIdRuntime.ScriptIdId of the script to edit.
scriptSourcestringNew content of the script.
dryRun (optional)booleanIf true the change will not actually be applied. Dry run may be used to get result description without actually modifying the code.
allowTopFrameEditing (optional)booleanIf 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

NameTypeDescription
callFramesarrayNew stack trace in case editing has happened while VM was stopped.
stackChangedbooleanWhether current call stack was modified after applying the changes.
asyncStackTraceRuntime.StackTraceAsync stack trace, if any.
asyncStackTraceIdRuntime.StackTraceIdAsync stack trace, if any.
statusstringWhether the operation was successful or not. Only `Ok` denotes a successful live edit while the other enum variants denote why the live edit failed.
exceptionDetailsRuntime.ExceptionDetailsException 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"}