Skip to content

Commit

Permalink
Moved backend injection logic to content script
Browse files Browse the repository at this point in the history
  • Loading branch information
onionymous committed Sep 11, 2019
1 parent c93038f commit 788036c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/react-devtools-extensions/src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}" }, "*");
})()
`;

Expand Down
6 changes: 3 additions & 3 deletions packages/react-devtools-extensions/src/injectGlobalHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
);
);

0 comments on commit 788036c

Please sign in to comment.