|
3 | 3 | To hack on the plugin: |
4 | 4 |
|
5 | 5 | - run `npm install` |
| 6 | +- run `webpack --config webpack.backend.js` in this directory |
6 | 7 | - run `webpack` or `webpack --watch` in this directory |
7 | 8 | - Go to `chrome://extensions`, check "developer mode", and click "Load |
8 | 9 | unpacked extension", and select this directory |
9 | 10 | - Hack away! |
10 | 11 |
|
11 | | -Generally, changes to the UI will auto-propagate (close devtools and re-open |
12 | | -them). If you change the background script or injector, you'll have to reload |
13 | | -the extension from the extensions page. |
| 12 | +Generally, changes to the UI will auto-propagate if you have `webpack --watch` |
| 13 | +on (close devtools and re-open them). If you change the background script or |
| 14 | +injector, you might have to reload the extension from the extensions page. |
| 15 | + |
| 16 | +## Insulating the environment |
| 17 | + |
| 18 | +React Devtools has part of the code (the backend + agent) running in the same |
| 19 | +javascript context as the inspected page, which makes the code vulnerable to |
| 20 | +environmental inconsistencies. For example, the backend uses the es6 `Map` |
| 21 | +class and normally expects it to be available in the global scope. If a user |
| 22 | +script has overridden this, the backend breaks. |
| 23 | + |
| 24 | +To prevent this, the content script [`src/GlobalHook.js`](src/GlobalHook.js), |
| 25 | +which runs before any user js, saves the native values we depend on to the |
| 26 | +`__REACT_DEVTOOLS_GLOBAL_HOOK__` global. These are: |
| 27 | + |
| 28 | +- Set |
| 29 | +- Map |
| 30 | +- WeakMap |
| 31 | +- Object.create |
| 32 | + |
| 33 | +Then in `webpack.backend.js`, these saved values are substituted for the |
| 34 | +globally referenced name (e.g. `Map` gets replaced with |
| 35 | +`window.__REACT_DEVTOOLS_GLOBAL_HOOK__.nativeMap`). |
| 36 | + |
| 37 | +## Fixing document.create |
| 38 | + |
| 39 | +React Native sets `document.createElement` to `null` in order to convince js |
| 40 | +libs that they are not running in a browser environment while `debug in |
| 41 | +chrome` is enabled. |
| 42 | + |
| 43 | +To deal with this, [`src/inject.js`](src/inject.js) calls |
| 44 | +`document.constructor.prototype.createElement` when it needs to create a |
| 45 | +`<script>` tag. |
14 | 46 |
|
0 commit comments