|
|
|
@ -35,6 +35,7 @@ export class Page extends HTMLElement { |
|
|
|
constructor() { |
|
|
|
super() |
|
|
|
const shadow = this.attachShadow({mode: 'open'}) |
|
|
|
this.csp = "default-src 'self' 'unsafe-inline' 'unsafe-eval'" |
|
|
|
this.textArea = document.createElement('textarea') |
|
|
|
this.textArea.addEventListener('input', e => { |
|
|
|
this.body = e.target.value |
|
|
|
@ -80,16 +81,18 @@ export class Page extends HTMLElement { |
|
|
|
const wrap = document.createElement('div') |
|
|
|
this.shadowRoot.appendChild(wrap) |
|
|
|
const tmp = document.createElement('iframe') |
|
|
|
tmp.sandbox = "allow-same-origin allow-scripts" |
|
|
|
const url = new URL( |
|
|
|
'/-/frame', location.href |
|
|
|
) |
|
|
|
url.searchParams.set( |
|
|
|
'csp', |
|
|
|
"default-src 'self' 'unsafe-inline' 'unsafe-eval'" |
|
|
|
) |
|
|
|
url.searchParams.set('html', frameHtml) |
|
|
|
tmp.src = url.href |
|
|
|
if (this.csp !== undefined) { |
|
|
|
tmp.sandbox = "allow-same-origin allow-scripts" |
|
|
|
const url = new URL( |
|
|
|
'/-/frame', location.href |
|
|
|
) |
|
|
|
url.searchParams.set('csp', this.csp) |
|
|
|
url.searchParams.set('html', frameHtml) |
|
|
|
tmp.src = url.href |
|
|
|
} else { |
|
|
|
tmp.sandbox = "allow-scripts" |
|
|
|
tmp.srcdoc = frameHtml |
|
|
|
} |
|
|
|
wrap.insertAdjacentHTML( |
|
|
|
'beforeend', tmp.outerHTML |
|
|
|
) |
|
|
|
@ -97,7 +100,7 @@ export class Page extends HTMLElement { |
|
|
|
this.frame = frames[frames.length - 1] |
|
|
|
this.textArea.addEventListener('blur', e => { |
|
|
|
const msg = ['srcdoc', e.target.value] |
|
|
|
this.frame.contentWindow.postMessage(msg) |
|
|
|
this.frame.contentWindow.postMessage(msg, '*') |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|