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

Commit ca8cb69

Browse files
Workaround (attempt 2) for firefox bug where the global object for content scripts gets redefined if the content script executes very early
A workaround for this bug was attempted in 721995e however this was not enough for all situations. The new workaround should be more robust
1 parent 4cc9258 commit ca8cb69

10 files changed

Lines changed: 30 additions & 13 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
2+
const registerRunnerModule = require('../../../content-register');
23

3-
openRunnerRegisterRunnerModule('assert', async ({getModule}) => {
4+
registerRunnerModule('assert', async ({getModule}) => {
45
const chai = await getModule('chai');
56
return chai.assert;
67
});
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const chai = require('../chai');
3+
const registerRunnerModule = require('../../../content-register');
34

4-
openRunnerRegisterRunnerModule('chai', () => {
5+
registerRunnerModule('chai', () => {
56
return chai();
67
});

runner-modules/content-register.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* global window:false */
2+
'use strict';
3+
4+
const registerRunnerModule = (...args) => {
5+
window.dispatchEvent(new window.Event('openrunnerinitmoduleframework'));
6+
return window.openRunnerRegisterRunnerModule(...args);
7+
};
8+
9+
module.exports = registerRunnerModule;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global window, document */
22
'use strict';
3-
3+
const registerRunnerModule = require('../../../content-register');
44
const log = require('../../../../lib/logger')({hostname: 'content', MODULE: 'contentEvents/content/index'});
55

66
const SLOW_PAINT_THRESHOLD = 50; // 60hz = 16.6...ms
@@ -10,7 +10,7 @@ const SLOW_PAINT_THRESHOLD = 50; // 60hz = 16.6...ms
1010
const requestAnimationFrame = callback => window.requestAnimationFrame(callback);
1111
const timing = () => window.performance.timing;
1212

13-
openRunnerRegisterRunnerModule('contentEvents', async ({getModule}) => {
13+
registerRunnerModule('contentEvents', async ({getModule}) => {
1414
const {scriptResult, TimePoint} = await getModule('runResult');
1515
let lastAnimationFrame = null;
1616

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
const {click} = require('./mouse');
33
const {keyboardKeys, keyboardTextInput} = require('./keyboard');
44
const {focus} = require('./focus');
5+
const registerRunnerModule = require('../../../content-register');
56

67
const DEFAULT_MOUSE_DOWN_DURATION = 64;
78
const DEFAULT_KEY_INTERVAL = 10;
89
const DEFAULT_KEY_DOWN_DURATION = 5;
910

10-
openRunnerRegisterRunnerModule('eventSimulation', async ({getModule}) => {
11+
registerRunnerModule('eventSimulation', async ({getModule}) => {
1112
const {scriptResult} = await getModule('runResult');
1213

1314
return Object.freeze({
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
2+
const registerRunnerModule = require('../../../content-register');
23

3-
openRunnerRegisterRunnerModule('expect', async ({getModule}) => {
4+
registerRunnerModule('expect', async ({getModule}) => {
45
const chai = await getModule('chai');
56
return chai.expect;
67
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22
/* global document:false */
3-
43
const {observeDocument} = require('./mutationEvents');
4+
const registerRunnerModule = require('../../../content-register');
55

6-
openRunnerRegisterRunnerModule('mutationEvents', async ({getModule}) => {
6+
registerRunnerModule('mutationEvents', async ({getModule}) => {
77
const {scriptResult} = await getModule('runResult');
88
observeDocument(document, scriptResult);
99
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
2-
32
const {transactionAbortedError} = require('../../../../lib/scriptErrors');
43
const TimePoint = require('../TimePoint');
54
const TimePeriod = require('../TimePeriod');
65
const Event = require('../Event');
76
const Transaction = require('../Transaction');
87
const RunResult = require('../RunResult');
98
const log = require('../../../../lib/logger')({hostname: 'content', MODULE: 'runResult/content/index'});
9+
const registerRunnerModule = require('../../../content-register');
1010

11-
openRunnerRegisterRunnerModule('runResult', ({eventEmitter, rpc}) => {
11+
registerRunnerModule('runResult', ({eventEmitter, rpc}) => {
1212
TimePoint.setCounterFunc(() => ({
1313
backgroundCounter: undefined,
1414
scriptCounter: undefined,

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,15 @@ try {
8686

8787
window.openRunnerRegisterRunnerModule = openRunnerRegisterRunnerModule;
8888
window.addEventListener('message', handleWindowMessage, false);
89-
// Workaround for firefox bug (last tested to occur in v57)
89+
// Workaround for firefox bug (last tested to occur in v57 and v65)
9090
// it seems that sometimes this content script is executed so early that firefox still has to perform some kind of house keeping,
9191
// which causes our global variable to disappear. assigning the global variable again in a microtask works around this bug.
9292
Promise.resolve().then(() => {
9393
window.openRunnerRegisterRunnerModule = openRunnerRegisterRunnerModule;
94-
window.addEventListener('message', handleWindowMessage, false); // has no effect if already added
94+
});
95+
window.addEventListener('openrunnerinitmoduleframework', e => {
96+
e.stopImmediatePropagation();
97+
window.openRunnerRegisterRunnerModule = openRunnerRegisterRunnerModule;
9598
});
9699

97100
log.debug('Initialized... Notifying the background script');

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ const Bluefox = require('bluefox');
44

55
const log = require('../../../../lib/logger')({hostname: 'content', MODULE: 'wait/content/index'});
66
const trackRunResultEvents = require('./trackRunResultEvents');
7+
const registerRunnerModule = require('../../../content-register');
78

8-
openRunnerRegisterRunnerModule('wait', async ({eventEmitter, getModule}) => {
9+
registerRunnerModule('wait', async ({eventEmitter, getModule}) => {
910
const runResultModule = await getModule('runResult');
1011
const bluefox = new Bluefox();
1112
const wait = bluefox.target(window);

0 commit comments

Comments
 (0)