File tree 6 files changed +27
-14
lines changed
react-devtools-extensions/src
react-devtools-inline/src
react-devtools-shared/src/backend 6 files changed +27
-14
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ type ConnectOptions = {
32
32
33
33
installHook ( window ) ;
34
34
35
- const hook : DevToolsHook = window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ;
35
+ const hook : ? DevToolsHook = window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ;
36
36
37
37
let savedComponentFilters : Array < ComponentFilter > = getDefaultComponentFilters ( ) ;
38
38
@@ -48,6 +48,10 @@ function debug(methodName: string, ...args) {
48
48
}
49
49
50
50
export function connectToDevTools ( options : ?ConnectOptions ) {
51
+ if ( hook == null ) {
52
+ // DevTools didn't get injected into this page (maybe b'c of the contentType).
53
+ return ;
54
+ }
51
55
const {
52
56
host = 'localhost' ,
53
57
nativeStyleEditorValidAttributes,
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ function welcome(event) {
22
22
window . addEventListener ( 'message' , welcome ) ;
23
23
24
24
function setup ( hook ) {
25
+ if ( hook == null ) {
26
+ // DevTools didn't get injected into this page (maybe b'c of the contentType).
27
+ return ;
28
+ }
25
29
const Agent = require ( 'react-devtools-shared/src/backend/agent' ) . default ;
26
30
const Bridge = require ( 'react-devtools-shared/src/bridge' ) . default ;
27
31
const { initBackend} = require ( 'react-devtools-shared/src/backend' ) ;
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ if (sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
88
88
89
89
// Inject a __REACT_DEVTOOLS_GLOBAL_HOOK__ global for React to interact with.
90
90
// Only do this for HTML documents though, to avoid e.g. breaking syntax highlighting for XML docs.
91
- if ( document . contentType === 'text/html' ) {
91
+ if ( 'text/html' === document . contentType ) {
92
92
injectCode (
93
93
';(' +
94
94
installHook . toString ( ) +
Original file line number Diff line number Diff line change @@ -271,7 +271,7 @@ function createPanelIfReactLoaded() {
271
271
// When the user chooses a different node in the browser Elements tab,
272
272
// copy it over to the hook object so that we can sync the selection.
273
273
chrome . devtools . inspectedWindow . eval (
274
- '(window.__REACT_DEVTOOLS_GLOBAL_HOOK__.$0 !== $0) ?' +
274
+ '(window.__REACT_DEVTOOLS_GLOBAL_HOOK__ && window.__REACT_DEVTOOLS_GLOBAL_HOOK__ .$0 !== $0) ?' +
275
275
'(window.__REACT_DEVTOOLS_GLOBAL_HOOK__.$0 = $0, true) :' +
276
276
'false' ,
277
277
( didSelectionChange , evalError ) => {
Original file line number Diff line number Diff line change @@ -73,17 +73,18 @@ function finishActivation(contentWindow: window) {
73
73
const agent = new Agent ( bridge ) ;
74
74
75
75
const hook = contentWindow . __REACT_DEVTOOLS_GLOBAL_HOOK__ ;
76
-
77
- initBackend ( hook , agent , contentWindow ) ;
78
-
79
- // Setup React Native style editor if a renderer like react-native-web has injected it.
80
- if ( hook . resolveRNStyle ) {
81
- setupNativeStyleEditor (
82
- bridge ,
83
- agent ,
84
- hook . resolveRNStyle ,
85
- hook . nativeStyleEditorValidAttributes ,
86
- ) ;
76
+ if ( hook ) {
77
+ initBackend ( hook , agent , contentWindow ) ;
78
+
79
+ // Setup React Native style editor if a renderer like react-native-web has injected it.
80
+ if ( hook . resolveRNStyle ) {
81
+ setupNativeStyleEditor (
82
+ bridge ,
83
+ agent ,
84
+ hook . resolveRNStyle ,
85
+ hook . nativeStyleEditorValidAttributes ,
86
+ ) ;
87
+ }
87
88
}
88
89
}
89
90
Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ export function initBackend(
19
19
agent : Agent ,
20
20
global : Object ,
21
21
) : ( ) => void {
22
+ if ( hook == null ) {
23
+ // DevTools didn't get injected into this page (maybe b'c of the contentType).
24
+ return ( ) => { } ;
25
+ }
22
26
const subs = [
23
27
hook . sub (
24
28
'renderer-attached' ,
You can’t perform that action at this time.
0 commit comments