fix: use Runtime.evaluate fallback when setScriptSource is deprecated

Chrome deprecated Debugger.setScriptSource in Chrome 142+ (removed in 145).
Falls back to Runtime.evaluate to re-execute modified scripts, which
works for scripts defining functions at global scope.
This commit is contained in:
Tommy D. Rossi
2026-02-05 16:56:27 +01:00
parent 0eaf771c57
commit 3f24ac1d8f
+29
View File
@@ -304,6 +304,11 @@ export class Editor {
}
return { success: true }
}
// Chrome deprecated Debugger.setScriptSource in Chrome 142+ (Feb 2026)
// Use Runtime.evaluate as fallback to re-execute the modified script
// This works for scripts that define functions at global scope
try {
const response = await this.cdp.send('Debugger.setScriptSource', {
scriptId: id.scriptId,
scriptSource: content,
@@ -313,6 +318,30 @@ export class Editor {
this.sourceCache.set(id.scriptId, content)
}
return { success: true, stackChanged: response.stackChanged }
} catch (error: unknown) {
const errorMessage = error instanceof Error ? error.message : String(error)
// Check if setScriptSource is deprecated/unavailable
if (errorMessage.includes('setScriptSource') || errorMessage.includes('-32000')) {
if (dryRun) {
// For dry run, just validate the syntax by parsing
await this.cdp.send('Runtime.compileScript', {
expression: content,
sourceURL: 'dry-run-validation',
persistScript: false,
})
return { success: true }
}
// Re-execute the entire script to override global functions
await this.cdp.send('Runtime.evaluate', {
expression: content,
returnByValue: false,
})
this.sourceCache.set(id.scriptId, content)
return { success: true, stackChanged: true }
}
throw error
}
}
/**