summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/tests/browser/newtabmessages_preview.html
blob: 4fe55132d6a4bc8053e42f7f85aeb092f2b5f89d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<html>
  <head>
    <meta charset="utf8">
    <title>Newtab WebChannel test</title>
  </head>
  <body>
    <script>
      let thumbURL = "https://example.com/browser/browser/components/newtab/tests/browser/blue_page.html";

      window.addEventListener("WebChannelMessageToContent", function(e) {
        if (e.detail.message && e.detail.message.type === "RECEIVE_THUMB") {
          if (e.detail.message.data.imgData && e.detail.message.data.url === thumbURL) {
            let reply = new window.CustomEvent("WebChannelMessageToChrome", {
              detail: JSON.stringify({
                id: "newtab",
                message: JSON.stringify({type: "responseAck"}),
              })
            });
            window.dispatchEvent(reply);
          }
        }
      }, true);

      document.onreadystatechange = function () {
        if (document.readyState === "complete") {
          let msg = new window.CustomEvent("WebChannelMessageToChrome", {
            detail: JSON.stringify({
              id: "newtab",
              message: JSON.stringify({type: "REQUEST_THUMB", data: thumbURL}),
            })
          });
          window.dispatchEvent(msg);
        }
      };
    </script>
  </body>
</html>