Moved backend injection logic to content script

This commit is contained in:
Stephanie Ding
2019-09-10 17:34:12 -07:00
parent c93038fabe
commit 788036c7ed
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -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}" }, "*");
})()
`;
+3 -3
View File
@@ -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,
);
);