GeezerVison is showing github.com — remove ability to inject arbitrary scripts · react/react@8a6cd3c
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/react-devtools-extensions/src
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/react-devtools-extensions/src/inject.js +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
2 | 2 |
|
3 | 3 | export default function inject(scriptName: string, done: ?Function) { |
4 | 4 | const source = ` |
| 5 | + // the prototype stuff is in case document.createElement has been modified |
5 | 6 | (function () { |
6 | | - window.postMessage({ source: 'react-devtools-inject-script', scriptName: "${scriptName}" }, "*"); |
| 7 | + var script = document.constructor.prototype.createElement.call(document, 'script'); |
| 8 | + script.src = "${scriptName}"; |
| 9 | + script.charset = "utf-8"; |
| 10 | + document.documentElement.appendChild(script); |
| 11 | + script.parentNode.removeChild(script); |
7 | 12 | })() |
8 | 13 | `; |
9 | 14 |
|
@@ -16,4 +21,4 @@ export default function inject(scriptName: string, done: ?Function) { |
16 | 21 | done(); |
17 | 22 | } |
18 | 23 | }); |
19 | | -} |
| 24 | +} |
Collapse file
Copy file name to clipboardExpand all lines: packages/react-devtools-extensions/src/injectGlobalHook.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,10 +31,10 @@ window.addEventListener('message', function(evt) { |
31 | 31 | reactBuildType: evt.data.reactBuildType, |
32 | 32 | }; |
33 | 33 | chrome.runtime.sendMessage(lastDetectionResult); |
34 | | - } else if (evt.data.source === 'react-devtools-inject-script' && evt.data.scriptName) { |
| 34 | + } else if (evt.data.source === 'react-devtools-inject-backend') { |
35 | 35 | //Inject the specified script |
36 | 36 | var script = document.constructor.prototype.createElement.call(document, 'script'); |
37 | | - script.src = evt.data.scriptName; |
| 37 | + script.src = chrome.runtime.getURL('build/backend.js'); |
38 | 38 | script.charset = "utf-8"; |
39 | 39 | document.documentElement.appendChild(script); |
40 | 40 | script.parentNode.removeChild(script); |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/react-devtools-extensions/src/main.js +12-1Lines changed: 12 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -135,7 +135,18 @@ function createPanelIfReactLoaded() { |
135 | 135 |
|
136 | 136 | // Initialize the backend only once the Store has been initialized. |
137 | 137 | // Otherwise the Store may miss important initial tree op codes. |
138 | | - inject(chrome.runtime.getURL('build/backend.js')); |
| 138 | + chrome.devtools.inspectedWindow.eval( |
| 139 | + `window.postMessage({ source: 'react-devtools-inject-backend' });`, |
| 140 | + function(response, error) { |
| 141 | + if (error) { |
| 142 | + console.log(error); |
| 143 | + } |
| 144 | + |
| 145 | + if (typeof done === 'function') { |
| 146 | + done(); |
| 147 | + } |
| 148 | + } |
| 149 | + ); |
139 | 150 |
|
140 | 151 | const viewElementSourceFunction = createViewElementSource( |
141 | 152 | bridge, |
|