1+ /**
2+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3+ *
4+ * This source code is licensed under the MIT license found in the
5+ * LICENSE file in the root directory of this source tree.
6+ *
7+ * @flow
8+ */
19/* global chrome */
210
311'use strict' ;
412
5- window . addEventListener ( 'pageshow' , function ( { target} ) {
13+ function injectProxy ( { target} : { target : any } ) {
614 // Firefox's behaviour for injecting this content script can be unpredictable
715 // While navigating the history, some content scripts might not be re-injected and still be alive
816 if ( ! window . __REACT_DEVTOOLS_PROXY_INJECTED__ ) {
@@ -14,15 +22,19 @@ window.addEventListener('pageshow', function ({target}) {
1422 // The backend waits to install the global hook until notified by the content script.
1523 // In the event of a page reload, the content script might be loaded before the backend manager is injected.
1624 // Because of this we need to poll the backend manager until it has been initialized.
17- const intervalID = setInterval ( ( ) => {
25+ const intervalID : IntervalID = setInterval ( ( ) => {
1826 if ( backendInitialized ) {
1927 clearInterval ( intervalID ) ;
2028 } else {
2129 sayHelloToBackendManager ( ) ;
2230 }
2331 } , 500 ) ;
2432 }
25- } ) ;
33+ }
34+
35+ window . addEventListener ( 'pagereveal' , injectProxy ) ;
36+ // For backwards compat with browsers not implementing `pagereveal` which is a fairly new event.
37+ window . addEventListener ( 'pageshow' , injectProxy ) ;
2638
2739window . addEventListener ( 'pagehide' , function ( { target} ) {
2840 if ( target !== window . document ) {
@@ -45,7 +57,7 @@ function sayHelloToBackendManager() {
4557 ) ;
4658}
4759
48- function handleMessageFromDevtools ( message ) {
60+ function handleMessageFromDevtools ( message : any ) {
4961 window . postMessage (
5062 {
5163 source : 'react-devtools-content-script' ,
@@ -55,7 +67,7 @@ function handleMessageFromDevtools(message) {
5567 ) ;
5668}
5769
58- function handleMessageFromPage ( event ) {
70+ function handleMessageFromPage ( event : any ) {
5971 if ( event . source !== window || ! event . data ) {
6072 return ;
6173 }
@@ -65,6 +77,7 @@ function handleMessageFromPage(event) {
6577 case 'react-devtools-bridge' : {
6678 backendInitialized = true ;
6779
80+ // $FlowFixMe[incompatible-use]
6881 port . postMessage ( event . data . payload ) ;
6982 break ;
7083 }
@@ -99,6 +112,8 @@ function connectPort() {
99112
100113 window . addEventListener ( 'message' , handleMessageFromPage ) ;
101114
115+ // $FlowFixMe[incompatible-use]
102116 port . onMessage . addListener ( handleMessageFromDevtools ) ;
117+ // $FlowFixMe[incompatible-use]
103118 port . onDisconnect . addListener ( handleDisconnect ) ;
104119}
0 commit comments