1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* globals catcher, callBackground, content */
6 /** This is a content script added to all screenshots.firefox.com pages, and allows the site to
7 communicate with the add-on */
11 this.sitehelper = (function () {
12 catcher.registerHandler(errorObj => {
13 callBackground("reportError", errorObj);
16 const capabilities = {};
17 function registerListener(name, func) {
18 capabilities[name] = name;
19 document.addEventListener(name, func);
22 function sendCustomEvent(name, detail) {
23 if (typeof detail === "object") {
24 // Note sending an object can lead to security problems, while a string
25 // is safe to transfer:
26 detail = JSON.stringify(detail);
28 document.dispatchEvent(new CustomEvent(name, { detail }));
33 catcher.watchFunction(() => {
34 // FIXME: reset some data in the add-on
40 catcher.watchFunction(event => {
41 catcher.watchPromise(callBackground("copyShotToClipboard", event.detail));
47 catcher.watchFunction(event => {
48 catcher.watchPromise(callBackground("showNotification", event.detail));
52 // Depending on the script loading order, the site might get the addon-present event,
53 // but probably won't - instead the site will ask for that event after it has loaded
55 "request-addon-present",
56 catcher.watchFunction(() => {
57 sendCustomEvent("addon-present", capabilities);
61 sendCustomEvent("addon-present", capabilities);