@@ -74,6 +74,8 @@ const { contentWindow } = iframe;
7474initializeBackend (contentWindow);
7575
7676// React application can be injected into <iframe> at any time now...
77+ // Note that this would need to be done via <script> tag injection,
78+ // as setting the src of the <iframe> would load a new page (withou the injected backend).
7779
7880// Initialize DevTools UI to listen to the hook we just installed.
7981// This returns a React component we can render anywhere in the parent window.
@@ -91,29 +93,33 @@ Sandboxed `iframe`s are also supported but require more complex initialization.
9193
9294** ` iframe.html ` **
9395``` js
94- import { activate , initialize } from ' react-devtools-inline/backend' ;
96+ import { activate , initialize } from " react-devtools-inline/backend" ;
9597
9698// The DevTooks hook needs to be installed before React is even required!
9799// The safest way to do this is probably to install it in a separate script tag.
98100initialize (window );
99101
100102// Wait for the frontend to let us know that it's ready.
101- window . addEventListener ( ' message ' , ({ data }) => {
103+ function onMessage ({ data }) {
102104 switch (data .type ) {
103- case ' activate' :
105+ case " activate-backend" :
106+ window .removeEventListener (" message" , onMessage);
107+
104108 activate (window );
105109 break ;
106110 default :
107111 break ;
108112 }
109- });
113+ }
114+
115+ window .addEventListener (" message" , onMessage);
110116```
111117
112118** ` main-window.html ` **
113119``` js
114- import { initialize } from ' react-devtools-inline/frontend' ;
120+ import { initialize } from " react-devtools-inline/frontend" ;
115121
116- const iframe = document .getElementById (' target' );
122+ const iframe = document .getElementById (" target" );
117123const { contentWindow } = iframe;
118124
119125// Initialize DevTools UI to listen to the iframe.
@@ -126,9 +132,9 @@ const DevTools = initialize(contentWindow);
126132iframe .onload = () => {
127133 contentWindow .postMessage (
128134 {
129- type: ' activate' ,
135+ type: " activate-backend "
130136 },
131- ' * '
137+ " * "
132138 );
133139};
134140```
0 commit comments