benfrancis / webview

A proposed HTML element and API to embed a web page inside a web page.
5 stars 0 forks source link

API for inspecting loaded content #8

Open Gozala opened 9 years ago

Gozala commented 9 years ago

For example atom-shell webview exposes API similar to frame scripts, that lets you interact with a DOM loaded in the web view and communicate with a web view embedder via message passing. For we already have a use case where we would like to grab twitter cards from the loaded page and only way for this would be to change an API to add more metadata. But this won't scale there always may be a new thing that embedder may need to do with in the web view. I think web view should be a able to contain a script element that would be evaled in the shell of the web view. I imagine something along these lines:

<webview>
    <script>
      const isTwitterCard = node =>
        node.tagName === "meta" &&
        node.getAttribute("name").startsWith("twitter:")
      const toInnerHTML = node => node.innerHTML

      content.addEventListener("DOMContentLoaded", () => {
        const cards = Array.from(document.querySelectorAll("meta"))
                          .filter(isTwitterCard)
        postMessage(cards.map(toInnerHTML))
      })
    </script>
</webview>
<script>
    document.querySelector("webview").addEventListener("message", handleCrads)
</script>
Gozala commented 9 years ago

Basically the way I propose model web view is like an iframe with nested content iframe with in it. So scripts could run in the outer iframe and messages could be exchanged with it like with regular iframes now. Outer iframe also should be able to interact with (content) sub iframe as more privileged iframes can with less privileged iframes if they're with in the same process.

Gozala commented 9 years ago

servo/servo#7083

Gozala commented 9 years ago

https://bugzilla.mozilla.org/show_bug.cgi?id=1198472