Skip to content

Commit 00aad0f

Browse files
authoredOct 9, 2024··
fix(extension): re-run script when execution context is empty (#626)
1 parent 8b15bde commit 00aad0f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed
 

‎packages/chrome-extension/src/devtools-panel.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,20 @@ function injectScript(scriptName: string, cb: () => void) {
6868
script.parentNode.removeChild(script);
6969
})()
7070
`
71-
chrome.devtools.inspectedWindow.eval(src, (res, err) => {
72-
if (err)
73-
console.error(err)
71+
let timeoutId: number = null!
72+
function execute() {
73+
clearTimeout(timeoutId)
74+
chrome.devtools.inspectedWindow.eval(src, (res, err) => {
75+
if (err) {
76+
// @ts-expect-error skip type check
77+
timeoutId = setTimeout(() => {
78+
execute()
79+
}, 100)
80+
return
81+
}
7482

75-
cb()
76-
})
83+
cb()
84+
})
85+
}
86+
execute()
7787
}

0 commit comments

Comments
 (0)
Please sign in to comment.