fix Runtime.enable race condition with event-based synchronization
Replace arbitrary sleep(200ms) with proper wait for Runtime.executionContextCreated event in the relay server. This ensures pages are fully ready before Runtime.enable returns to Playwright, fixing intermittent 'page not found' errors.
This commit is contained in:
@@ -232,7 +232,7 @@ async function handleCommand(msg: ExtensionCommandMessage): Promise<any> {
|
||||
}
|
||||
try {
|
||||
await chrome.debugger.sendCommand(debuggee, 'Runtime.disable')
|
||||
await sleep(400)
|
||||
await sleep(200)
|
||||
} catch (e) {
|
||||
logger.debug('Error disabling Runtime (ignoring):', e)
|
||||
}
|
||||
@@ -507,15 +507,7 @@ function handleConnectionClose(reason: string, code: number): void {
|
||||
return
|
||||
}
|
||||
|
||||
store.setState((state) => {
|
||||
const newTabs = new Map(state.tabs)
|
||||
for (const [tabId, tab] of newTabs) {
|
||||
if (tab.state === 'connected') {
|
||||
newTabs.set(tabId, { ...tab, state: 'connecting' })
|
||||
}
|
||||
}
|
||||
return { tabs: newTabs, connectionState: 'disconnected', errorText: undefined }
|
||||
})
|
||||
store.setState({ connectionState: 'disconnected', errorText: undefined })
|
||||
|
||||
if (tabs.size > 0) {
|
||||
logger.debug('Tabs still connected, triggering reconnection')
|
||||
|
||||
Reference in New Issue
Block a user