@@ -5,7 +5,7 @@ import {flushSync} from 'react-dom';
5
5
import { createRoot } from 'react-dom/client' ;
6
6
import Bridge from 'react-devtools-shared/src/bridge' ;
7
7
import Store from 'react-devtools-shared/src/devtools/store' ;
8
- import { getBrowserName , getBrowserTheme } from './utils' ;
8
+ import { IS_CHROME , IS_EDGE , getBrowserTheme } from './utils' ;
9
9
import { LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY } from 'react-devtools-shared/src/constants' ;
10
10
import { registerDevToolsEventLogger } from 'react-devtools-shared/src/registerDevToolsEventLogger' ;
11
11
import {
@@ -27,9 +27,6 @@ import {logEvent} from 'react-devtools-shared/src/Logger';
27
27
const LOCAL_STORAGE_SUPPORTS_PROFILING_KEY =
28
28
'React::DevTools::supportsProfiling' ;
29
29
30
- const isChrome = getBrowserName ( ) === 'Chrome' ;
31
- const isEdge = getBrowserName ( ) === 'Edge' ;
32
-
33
30
// rAF never fires on devtools_page (because it's in the background)
34
31
// https://bugs.chromium.org/p/chromium/issues/detail?id=1241986#c31
35
32
// Since we render React elements here, we need to polyfill it with setTimeout
@@ -176,10 +173,10 @@ function createPanelIfReactLoaded() {
176
173
177
174
store = new Store ( bridge , {
178
175
isProfiling,
179
- supportsReloadAndProfile : isChrome || isEdge ,
176
+ supportsReloadAndProfile : IS_CHROME || IS_EDGE ,
180
177
supportsProfiling,
181
178
// At this time, the timeline can only parse Chrome performance profiles.
182
- supportsTimeline : isChrome ,
179
+ supportsTimeline : IS_CHROME ,
183
180
supportsTraceUpdates : true ,
184
181
} ) ;
185
182
if ( ! isProfiling ) {
@@ -188,14 +185,26 @@ function createPanelIfReactLoaded() {
188
185
189
186
// Initialize the backend only once the Store has been initialized.
190
187
// Otherwise the Store may miss important initial tree op codes.
191
- chrome . devtools . inspectedWindow . eval (
192
- `window.postMessage({ source: 'react-devtools-inject-backend' }, '*');` ,
193
- function ( response , evalError ) {
194
- if ( evalError ) {
195
- console . error ( evalError ) ;
196
- }
197
- } ,
198
- ) ;
188
+ if ( IS_CHROME || IS_EDGE ) {
189
+ chrome . runtime . sendMessage ( {
190
+ source : 'react-devtools-main' ,
191
+ payload : {
192
+ type : 'react-devtools-inject-backend' ,
193
+ tabId,
194
+ } ,
195
+ } ) ;
196
+ } else {
197
+ // Firefox does not support executing script in ExecutionWorld.MAIN from content script.
198
+ // see prepareInjection.js
199
+ chrome . devtools . inspectedWindow . eval (
200
+ `window.postMessage({ source: 'react-devtools-inject-backend' }, '*');` ,
201
+ function ( response , evalError ) {
202
+ if ( evalError ) {
203
+ console . error ( evalError ) ;
204
+ }
205
+ } ,
206
+ ) ;
207
+ }
199
208
200
209
const viewAttributeSourceFunction = ( id , path ) => {
201
210
const rendererID = store . getRendererIDForElement ( id ) ;
@@ -255,7 +264,7 @@ function createPanelIfReactLoaded() {
255
264
// For some reason in Firefox, chrome.runtime.sendMessage() from a content script
256
265
// never reaches the chrome.runtime.onMessage event listener.
257
266
let fetchFileWithCaching = null ;
258
- if ( isChrome ) {
267
+ if ( IS_CHROME ) {
259
268
const fetchFromNetworkCache = ( url , resolve , reject ) => {
260
269
// Debug ID allows us to avoid re-logging (potentially long) URL strings below,
261
270
// while also still associating (potentially) interleaved logs with the original request.
@@ -463,7 +472,7 @@ function createPanelIfReactLoaded() {
463
472
let needsToSyncElementSelection = false ;
464
473
465
474
chrome . devtools . panels . create (
466
- isChrome || isEdge ? '⚛️ Components' : 'Components' ,
475
+ IS_CHROME || IS_EDGE ? '⚛️ Components' : 'Components' ,
467
476
'' ,
468
477
'panel.html' ,
469
478
extensionPanel => {
@@ -494,7 +503,7 @@ function createPanelIfReactLoaded() {
494
503
) ;
495
504
496
505
chrome . devtools . panels . create (
497
- isChrome || isEdge ? '⚛️ Profiler' : 'Profiler' ,
506
+ IS_CHROME || IS_EDGE ? '⚛️ Profiler' : 'Profiler' ,
498
507
'' ,
499
508
'panel.html' ,
500
509
extensionPanel => {
0 commit comments