firefox-sender-probe.js

1.0 KB · raw

1(() => {2  const SOURCE = "peach-firefox-sender-probe";3  document.documentElement.dataset.peachFirefoxSenderProbe = "ready"; // Proves Firefox injected this content script before the page probe runs.4  const ALLOWED_TYPES = new Set(["GET_ENTRIES", "GET_RECOVERY_WORDS", "GET_SETTINGS"]);56  window.addEventListener("message", async (event) => {7    let request;8    try {9      request = JSON.parse(event.data);10    } catch {11      return;12    }13    const { id, message } = request ?? {};14    if (request?.source !== SOURCE || typeof id !== "string" || !message) return;1516    let response;17    try {18      response = message.type === "STORAGE_SESSION"19        ? await chrome.storage.session.get("peach_session_dk")20        : ALLOWED_TYPES.has(message.type)21          ? await chrome.runtime.sendMessage(message)22          : undefined;23      if (response === undefined) return;24    } catch (error) {25      response = { ok: false, error: String(error) };26    }27    window.postMessage(JSON.stringify({ source: `${SOURCE}:response`, id, response }), "*");28  });29})();