Read Context of Frame

We send a message to the Frame asking it to send us info about the page surrounding it. mdn

window.addEventListener("message", handler) let message = { action:"sendFrameContext" } window.parent.postMessage(message, "*")

We stop listening then process the data we got.

function handler ({data}) { if (data.action == "frameContext") { window.removeEventListener("message", handler) const {slug, item, page} = data show(page) } }

The page we show is the page on the screen which might be a ghost, maybe retrieved from history.

function show (page) { let plugins = page.story.map(item => item.type) let html = `<pre>${plugins.join("\n")}</pre>` output.innerHTML = html }

function frameContext() { return new Promise(resolve => { let handler = event => { let {data} = event if (!data.action == "frameContext") return window.removeEventListener('message',handler) resolve(data) } window.addEventListener('message',handler) window.parent.postMessage({action:"sendFrameContext"},"*") }) }