import { BrowserApi } from "../../platform/browser/browser-api"; import { Fido2Service as Fido2ServiceInterface } from "./abstractions/fido2.service"; export default class Fido2Service implements Fido2ServiceInterface { async init() { const tabs = await BrowserApi.tabsQuery({}); tabs.forEach((tab) => { if (tab.url?.startsWith("https")) { this.injectFido2ContentScripts({ tab } as chrome.runtime.MessageSender); } }); BrowserApi.addListener(chrome.runtime.onConnect, (port) => { if (port.name === "fido2ContentScriptReady") { port.postMessage({ command: "fido2ContentScriptInit" }); } }); } /** * Injects the FIDO2 content script into the current tab. * @param {chrome.runtime.MessageSender} sender * @returns {Promise} */ async injectFido2ContentScripts(sender: chrome.runtime.MessageSender): Promise { await BrowserApi.executeScriptInTab(sender.tab.id, { file: "content/fido2/content-script.js", frameId: sender.frameId, runAt: "document_start", }); } }