Moved backend injection logic to content script
Stephanie Ding committed
Sep 10, 2019 at 17:34 UTC
788036c7ed51fa2a7fc021bbe3807762072dee33
2 files changed
+4
-4
packages/react-devtools-extensions/src/inject.js
+1
-1
@@ -3,7 +3,7 @@
3
export default function inject(scriptName: string, done: ? Function) {
4
const source = `
5
(function () {
6
- window.postMessage({ source: 'react-devtools-inject-backend', type: "FROM_PAGE", text: "Hello from the webpage!" }, "*");
6
+ window.postMessage({ source: 'react-devtools-inject-script', scriptName: "${scriptName}" }, "*");
7
})()
8
`;
9
packages/react-devtools-extensions/src/injectGlobalHook.js
+3
-3
@@ -37,10 +37,10 @@ window.addEventListener('message', function(evt) {
37
reactBuildType: evt.data.reactBuildType,
38
};
39
chrome.runtime.sendMessage(lastDetectionResult);
40
- } else if (evt.data.source === 'react-devtools-inject-backend') {
40
+ } else if (evt.data.source === 'react-devtools-inject-backend' && evt.data.scriptName) {
41
//Inject backend
42
var script = document.constructor.prototype.createElement.call(document, 'script');
43
- script.src = chrome.runtime.getURL('build/backend.js');
43
+ script.src = evt.data.scriptName;
44
script.charset = "utf-8";
45
document.documentElement.appendChild(script);
46
script.parentNode.removeChild(script);
@@ -97,4 +97,4 @@ if (sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
97
// devtools are installed (and skip its suggestion to install the devtools).
98
injectCode(
99
';(' + installHook.toString() + '(window))' + saveNativeValues + detectReact,
100
-);
\ No newline at end of file
100
+);