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:
@@ -304,15 +304,44 @@ export class Editor {
|
|||||||
}
|
}
|
||||||
return { success: true }
|
return { success: true }
|
||||||
}
|
}
|
||||||
const response = await this.cdp.send('Debugger.setScriptSource', {
|
|
||||||
scriptId: id.scriptId,
|
// Chrome deprecated Debugger.setScriptSource in Chrome 142+ (Feb 2026)
|
||||||
scriptSource: content,
|
// Use Runtime.evaluate as fallback to re-execute the modified script
|
||||||
dryRun,
|
// This works for scripts that define functions at global scope
|
||||||
})
|
try {
|
||||||
if (!dryRun) {
|
const response = await this.cdp.send('Debugger.setScriptSource', {
|
||||||
this.sourceCache.set(id.scriptId, content)
|
scriptId: id.scriptId,
|
||||||
|
scriptSource: content,
|
||||||
|
dryRun,
|
||||||
|
})
|
||||||
|
if (!dryRun) {
|
||||||
|
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
|
||||||
}
|
}
|
||||||
return { success: true, stackChanged: response.stackChanged }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user