Skip to content

Commit c937b98

Browse files
authored
fix: timing issue (#24)
1 parent 1dd81fa commit c937b98

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

template/content-script.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,18 @@ function unwrapFunctionCode(fn) {
2020
injectScript(
2121
unwrapFunctionCode(function () {
2222
const devtoolsKey = "@pbkit/devtools";
23-
let resolve;
24-
const devtoolsConfigPromise = new Promise((res) => (resolve = res));
2523
if (!window[devtoolsKey]) {
26-
window[devtoolsKey] = [resolve];
24+
window[devtoolsKey] = [register];
2725
} else if (Array.isArray(window[devtoolsKey])) {
28-
window[devtoolsKey].push(resolve);
26+
window[devtoolsKey].push(register);
2927
} else {
30-
resolve(window[devtoolsKey]);
28+
register(window[devtoolsKey]);
3129
}
32-
devtoolsConfigPromise.then((devtoolsConfig) => {
30+
function register(devtoolsConfig) {
3331
devtoolsConfig.on("*", (event, type) => {
3432
const message = { target: "@pbkit/devtools/panel", event, type };
3533
window.postMessage(message, "*");
3634
});
37-
console.log("Successfully connected with @pbkit/devtools/panel");
38-
});
35+
}
3936
})
4037
);

0 commit comments

Comments
 (0)