11/* global chrome */
22
33import nullthrows from 'nullthrows' ;
4- import { installHook } from 'react-devtools-shared/src/hook' ;
5- import { SESSION_STORAGE_RELOAD_AND_PROFILE_KEY } from 'react-devtools-shared/src/constants' ;
6- import { sessionStorageGetItem } from 'react-devtools-shared/src/storage' ;
4+ import {
5+ installHook
6+ } from 'react-devtools-shared/src/hook' ;
7+ import {
8+ SESSION_STORAGE_RELOAD_AND_PROFILE_KEY
9+ } from 'react-devtools-shared/src/constants' ;
10+ import {
11+ sessionStorageGetItem
12+ } from 'react-devtools-shared/src/storage' ;
713
814function injectCode ( code ) {
915 const script = document . createElement ( 'script' ) ;
@@ -24,16 +30,21 @@ let lastDetectionResult;
2430// So instead, the hook will use postMessage() to pass message to us here.
2531// And when this happens, we'll send a message to the "background page".
2632window . addEventListener ( 'message' , function ( evt ) {
27- if (
28- evt . source === window &&
29- evt . data &&
30- evt . data . source === 'react-devtools-detector'
31- ) {
32- lastDetectionResult = {
33- hasDetectedReact : true ,
34- reactBuildType : evt . data . reactBuildType ,
35- } ;
36- chrome . runtime . sendMessage ( lastDetectionResult ) ;
33+ if ( evt . source === window && evt . data ) {
34+ if ( evt . data . source === 'react-devtools-detector' ) {
35+ lastDetectionResult = {
36+ hasDetectedReact : true ,
37+ reactBuildType : evt . data . reactBuildType ,
38+ } ;
39+ chrome . runtime . sendMessage ( lastDetectionResult ) ;
40+ } else if ( evt . data . source === 'react-devtools-inject-backend' ) {
41+ //Inject backend
42+ var script = document . constructor . prototype . createElement . call ( document , 'script' ) ;
43+ script . src = chrome . runtime . getURL ( 'build/backend.js' ) ;
44+ script . charset = "utf-8" ;
45+ document . documentElement . appendChild ( script ) ;
46+ script . parentNode . removeChild ( script ) ;
47+ }
3748 }
3849} ) ;
3950
@@ -86,4 +97,4 @@ if (sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
8697// devtools are installed (and skip its suggestion to install the devtools).
8798injectCode (
8899 ';(' + installHook . toString ( ) + '(window))' + saveNativeValues + detectReact ,
89- ) ;
100+ ) ;
0 commit comments