|
2 | 2 |
|
3 | 3 | 'use strict';
|
4 | 4 |
|
5 |
| -let port = null; |
6 |
| -let backendInitialized: boolean = false; |
7 |
| - |
8 |
| -connectPort(); |
9 |
| -sayHelloToBackendManager(); |
| 5 | +window.addEventListener('pageshow', function ({target}) { |
| 6 | + // Firefox's behaviour for injecting this content script can be unpredictable |
| 7 | + // While navigating the history, some content scripts might not be re-injected and still be alive |
| 8 | + if (!window.__REACT_DEVTOOLS_PROXY_INJECTED__) { |
| 9 | + window.__REACT_DEVTOOLS_PROXY_INJECTED__ = true; |
10 | 10 |
|
11 |
| -// The backend waits to install the global hook until notified by the content script. |
12 |
| -// In the event of a page reload, the content script might be loaded before the backend manager is injected. |
13 |
| -// Because of this we need to poll the backend manager until it has been initialized. |
14 |
| -const intervalID = setInterval(() => { |
15 |
| - if (backendInitialized) { |
16 |
| - clearInterval(intervalID); |
17 |
| - } else { |
| 11 | + connectPort(); |
18 | 12 | sayHelloToBackendManager();
|
| 13 | + |
| 14 | + // The backend waits to install the global hook until notified by the content script. |
| 15 | + // In the event of a page reload, the content script might be loaded before the backend manager is injected. |
| 16 | + // Because of this we need to poll the backend manager until it has been initialized. |
| 17 | + const intervalID = setInterval(() => { |
| 18 | + if (backendInitialized) { |
| 19 | + clearInterval(intervalID); |
| 20 | + } else { |
| 21 | + sayHelloToBackendManager(); |
| 22 | + } |
| 23 | + }, 500); |
| 24 | + } |
| 25 | +}); |
| 26 | + |
| 27 | +window.addEventListener('pagehide', function ({target}) { |
| 28 | + if (target !== window.document) { |
| 29 | + return; |
19 | 30 | }
|
20 |
| -}, 500); |
| 31 | + |
| 32 | + delete window.__REACT_DEVTOOLS_PROXY_INJECTED__; |
| 33 | +}); |
| 34 | + |
| 35 | +let port = null; |
| 36 | +let backendInitialized: boolean = false; |
21 | 37 |
|
22 | 38 | function sayHelloToBackendManager() {
|
23 | 39 | window.postMessage(
|
|
0 commit comments