From 788036c7ed51fa2a7fc021bbe3807762072dee33 Mon Sep 17 00:00:00 2001 From: Stephanie Ding Date: Tue, 10 Sep 2019 17:34:12 -0700 Subject: [PATCH] Moved backend injection logic to content script --- packages/react-devtools-extensions/src/inject.js | 2 +- packages/react-devtools-extensions/src/injectGlobalHook.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-devtools-extensions/src/inject.js b/packages/react-devtools-extensions/src/inject.js index 02750dbb06a86..909a192b53e54 100644 --- a/packages/react-devtools-extensions/src/inject.js +++ b/packages/react-devtools-extensions/src/inject.js @@ -3,7 +3,7 @@ export default function inject(scriptName: string, done: ? Function) { const source = ` (function () { - window.postMessage({ source: 'react-devtools-inject-backend', type: "FROM_PAGE", text: "Hello from the webpage!" }, "*"); + window.postMessage({ source: 'react-devtools-inject-script', scriptName: "${scriptName}" }, "*"); })() `; diff --git a/packages/react-devtools-extensions/src/injectGlobalHook.js b/packages/react-devtools-extensions/src/injectGlobalHook.js index a06b9bbf62943..e35c675e1f29a 100644 --- a/packages/react-devtools-extensions/src/injectGlobalHook.js +++ b/packages/react-devtools-extensions/src/injectGlobalHook.js @@ -37,10 +37,10 @@ window.addEventListener('message', function(evt) { reactBuildType: evt.data.reactBuildType, }; chrome.runtime.sendMessage(lastDetectionResult); - } else if (evt.data.source === 'react-devtools-inject-backend') { + } else if (evt.data.source === 'react-devtools-inject-backend' && evt.data.scriptName) { //Inject backend var script = document.constructor.prototype.createElement.call(document, 'script'); - script.src = chrome.runtime.getURL('build/backend.js'); + script.src = evt.data.scriptName; script.charset = "utf-8"; document.documentElement.appendChild(script); script.parentNode.removeChild(script); @@ -97,4 +97,4 @@ if (sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') { // devtools are installed (and skip its suggestion to install the devtools). injectCode( ';(' + installHook.toString() + '(window))' + saveNativeValues + detectReact, -); \ No newline at end of file +);