|
2 | 2 |
|
3 | 3 | 'use strict'; |
4 | 4 |
|
| 5 | +window.addEventListener('unload', function ({target}) { |
| 6 | + if (target !== window.document) { |
| 7 | + return; |
| 8 | + } |
| 9 | + |
| 10 | + delete window.__REACT_DEVTOOLS_PROXY_INJECTED__; |
| 11 | +}); |
| 12 | + |
5 | 13 | let port = null; |
6 | 14 | let backendInitialized: boolean = false; |
7 | 15 |
|
8 | | -connectPort(); |
9 | | -sayHelloToBackendManager(); |
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 { |
18 | | - sayHelloToBackendManager(); |
19 | | - } |
20 | | -}, 500); |
21 | | - |
22 | 16 | function sayHelloToBackendManager() { |
23 | 17 | window.postMessage( |
24 | 18 | { |
@@ -76,3 +70,23 @@ function connectPort() { |
76 | 70 | port.onMessage.addListener(handleMessageFromDevtools); |
77 | 71 | port.onDisconnect.addListener(handleDisconnect); |
78 | 72 | } |
| 73 | + |
| 74 | +// Firefox's behaviour for injecting this content script can be unpredictable |
| 75 | +// While navigating the history, some content scripts might not be re-injected and still be alive |
| 76 | +if (!window.__REACT_DEVTOOLS_PROXY_INJECTED__) { |
| 77 | + window.__REACT_DEVTOOLS_PROXY_INJECTED__ = true; |
| 78 | + |
| 79 | + connectPort(); |
| 80 | + sayHelloToBackendManager(); |
| 81 | + |
| 82 | + // The backend waits to install the global hook until notified by the content script. |
| 83 | + // In the event of a page reload, the content script might be loaded before the backend manager is injected. |
| 84 | + // Because of this we need to poll the backend manager until it has been initialized. |
| 85 | + const intervalID = setInterval(() => { |
| 86 | + if (backendInitialized) { |
| 87 | + clearInterval(intervalID); |
| 88 | + } else { |
| 89 | + sayHelloToBackendManager(); |
| 90 | + } |
| 91 | + }, 500); |
| 92 | +} |
0 commit comments