1
1
import { initDevTools } from '@front'
2
2
import Bridge from '@utils/bridge'
3
- import { installHook } from '@back/hook'
4
3
5
- // const target = document.getElementById('target')
6
- // const targetWindow = target.contentWindow
7
-
8
- // lol
9
- // https://stackoverflow.com/questions/16194398/inject-a-javascript-function-into-an-iframe
10
- // const source = ';(' + installHook.toString() + ')(window)'
11
- // frames[0].window.eval(source)
12
- // console.log(targetWindow)
13
- // target.contentWindow.eval(source)
14
- // if (document instanceof HTMLDocument) {
15
- // console.log('### yes')
16
-
17
- // const script = document.createElement('script')
18
- // script.textContent = source
19
- // document.documentElement.appendChild(script)
20
- // script.parentNode.removeChild(script)
21
- // }
22
- // }
23
-
24
- /**
25
- * @param {HTMLDivElement } el - where to mount the vue app
26
- * @param {HTMLIFrameElement } iframe - the iframe
27
- */
28
- export function inlineDevtools ( el , iframe ) {
29
- function inject ( src , done ) {
30
- if ( ! src || src === 'false' ) {
31
- return done ( )
32
- }
33
- const script = iframe . contentDocument . createElement ( 'script' )
34
- script . src = src
35
- script . onload = done
36
- iframe . contentDocument . body . appendChild ( script )
37
- }
38
-
39
- const source = ';(' + installHook . toString ( ) + ')(window)'
40
- const targetWindow = iframe . contentWindow
41
- console . log ( targetWindow )
42
- targetWindow . eval ( source )
4
+ const target = document . getElementById ( 'target' )
5
+ const targetWindow = target . contentWindow
43
6
7
+ // 1. load user app
8
+ target . src = 'target.html'
9
+ target . onload = ( ) => {
10
+ // 2. init devtools
44
11
initDevTools ( {
45
- el : '#app' ,
46
12
connect ( cb ) {
47
13
// 3. called by devtools: inject backend
48
14
inject ( './build/backend.js' , ( ) => {
@@ -60,14 +26,16 @@ export function inlineDevtools(el, iframe) {
60
26
} ,
61
27
onReload ( reloadFn ) {
62
28
target . onload = reloadFn
63
- } ,
64
- el,
29
+ }
65
30
} )
66
31
}
67
32
68
- // 1. load user app
69
- // target.src = 'target.html'
70
- target . onload = ( ) => {
71
- inlineDevtools ( '#app' , document . getElementById ( 'target' ) )
33
+ function inject ( src , done ) {
34
+ if ( ! src || src === 'false' ) {
35
+ return done ( )
36
+ }
37
+ const script = target . contentDocument . createElement ( 'script' )
38
+ script . src = src
39
+ script . onload = done
40
+ target . contentDocument . body . appendChild ( script )
72
41
}
73
-
0 commit comments