browser/extensions/webcompat-reporter/test/browser/webcompat.html
author Mark Banner <standard8@mozilla.com>
Mon, 08 May 2017 10:29:47 +0100
changeset 408248 61f9d530898ae753cddeecc240ad1896b9b9b939
parent 408246 e1e81b129b5b389f59ccc2144573a7c7af728a2a
child 456502 5087f500aa3b143d1d62a6731ce77de76136230d
permissions -rw-r--r--
Bug 1362947 - Upgrade eslint-plugin-html to 2.0.3 to pick up --fix support. r=jaws MozReview-Commit-ID: 5fVG7akPnGM

<!DOCTYPE html>
<meta charset="utf-8">
<style>
 #screenshot-preview {width: 200px; height: 200px;}
</style>
<div id="url"></div>
<div id="screenshot-preview">Fail</div>
<script>
let params = new URL(location.href).searchParams;
let preview = document.getElementById("screenshot-preview");
let url = document.getElementById("url");
url.innerText = params.get("url");

function getBlobAsDataURL(blob) {
  return new Promise((resolve, reject) => {
    let reader = new FileReader();

    reader.addEventListener("error", (e) => {
      reject(`There was an error reading the blob: ${e.type}`);
    });

    reader.addEventListener("load", (e) => {
      resolve(e.target.result);
    });

    reader.readAsDataURL(blob);
  });
}

function setPreviewBG(backgroundData) {
  return new Promise((resolve) => {
    preview.style.background = `url(${backgroundData})`;
    resolve();
  });
}

function sendReceivedEvent() {
  window.dispatchEvent(new CustomEvent("ScreenshotReceived", {bubbles: true}));
}

window.addEventListener("message", function(event) {
  if (event.data instanceof Blob) {
    preview.innerText = "Pass";
  }

  getBlobAsDataURL(event.data).then(setPreviewBG).then(sendReceivedEvent);
});
</script>