Skip to content

Commit 3bd9f08

Browse files
committed
early attach in devtools extension so we can patch the console
1 parent 9d72644 commit 3bd9f08

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

packages/react-devtools-extensions/src/injectGlobalHook.js

+16-17
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,23 @@ window.__REACT_DEVTOOLS_GLOBAL_HOOK__.nativeWeakMap = WeakMap;
6767
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.nativeSet = Set;
6868
`;
6969

70-
// If we have just reloaded to profile, we need to inject the renderer interface before the app loads.
71-
if (sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
72-
const rendererURL = chrome.runtime.getURL('build/renderer.js');
73-
let rendererCode;
70+
// We need to inject the renderer interface before the app loads so we can patch the
71+
// console before initial render.
72+
const rendererURL = chrome.runtime.getURL('build/renderer.js');
73+
let rendererCode;
7474

75-
// We need to inject in time to catch the initial mount.
76-
// This means we need to synchronously read the renderer code itself,
77-
// and synchronously inject it into the page.
78-
// There are very few ways to actually do this.
79-
// This seems to be the best approach.
80-
const request = new XMLHttpRequest();
81-
request.addEventListener('load', function() {
82-
rendererCode = this.responseText;
83-
});
84-
request.open('GET', rendererURL, false);
85-
request.send();
86-
injectCode(rendererCode);
87-
}
75+
// We need to inject in time to catch the initial mount.
76+
// This means we need to synchronously read the renderer code itself,
77+
// and synchronously inject it into the page.
78+
// There are very few ways to actually do this.
79+
// This seems to be the best approach.
80+
const request = new XMLHttpRequest();
81+
request.addEventListener('load', function() {
82+
rendererCode = this.responseText;
83+
});
84+
request.open('GET', rendererURL, false);
85+
request.send();
86+
injectCode(rendererCode);
8887

8988
// Inject a __REACT_DEVTOOLS_GLOBAL_HOOK__ global for React to interact with.
9089
// Only do this for HTML documents though, to avoid e.g. breaking syntax highlighting for XML docs.

0 commit comments

Comments
 (0)