Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 721995e

Browse files
Workaround for firefox bug where the global object for content scripts gets redefined if the content script executes very early
Sadly, I was unable to recreate this issue in a test case
1 parent 4f79341 commit 721995e

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

runner-modules/tabs/lib/content/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ try {
3939
}
4040
});
4141

42-
window.openRunnerRegisterRunnerModule = async (moduleName, func) => {
42+
const openRunnerRegisterRunnerModule = async (moduleName, func) => {
4343
try {
4444
if (typeof func !== 'function') {
4545
throw Error('openRunnerRegisterRunnerModule(): Invalid `func`');
@@ -61,6 +61,14 @@ try {
6161
}
6262
};
6363

64+
window.openRunnerRegisterRunnerModule = openRunnerRegisterRunnerModule;
65+
// Workaround for firefox bug (last tested to occur in v57)
66+
// it seems that sometimes this content script is executed so early that firefox still has to perform some kind of house keeping,
67+
// which causes our global variable to disappear. assigning the global variable again in a microtask works around this bug.
68+
Promise.resolve().then(() => {
69+
window.openRunnerRegisterRunnerModule = openRunnerRegisterRunnerModule;
70+
});
71+
6472
log.debug('Initialized... Notifying the background script');
6573
rpc.notify('tabs.mainContentInit')
6674
.catch(err => log.error({err}, 'Unable to send tabs.mainContentInit to the background script'));

0 commit comments

Comments
 (0)