mozilla / remote-newtab

Remotely-hosted New Tab Page
https://mozilla.github.io/remote-newtab/src/
Mozilla Public License 2.0
15 stars 7 forks source link

add pagehide event listener on init for chrome target unload #194

Open oyiptong opened 8 years ago

oyiptong commented 8 years ago

Until we add functionality to WebChannels, In order for the chrome NewTabWebChannel bookkeeping to work, we need to send an event on pagehide.

Here's an example:

document.addEventListener("pagehide", function(e) {
  let msg = new window.CustomEvent("WebChannelMessageToChrome", {
    detail: {
      id: "dev-newtab",
      message: JSON.stringify({type: "pagehide"}),
    }
  });
  window.dispatchEvent(msg);
});