repl.it
@Kognise/

FakeCode

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const html = `
<script>
  popout.on('message', console.log)
  popout.send('test')
</script>
`

const toInject = '<script>(' + (() => {
  const target = window.opener || window.parent
  const listeners = {}
  window.popout = {
    send: (message) => target.postMessage({ type: 'message', payload: message }),
    on: (event, handler) => listeners[event]
      ? listeners[event].push(handler)
      : listeners[event] = [ handler ]
  }
}).toString() + ')()</script>'

const dataUrl = 'data:text/html;base64,' + btoa(toInject + html)

console.log(dataUrl)