"use strict"; import messageRouter from "./messageRouter"; const _ = browser.i18n.getMessage; browser.runtime.onInstalled.addListener(async details => { const initialOptions = { option_localMediaEnabled: true , option_localMediaServerPort: 9555 }; switch (details.reason) { // Set initial options case "install": browser.storage.sync.set({ options: initialOptions }); break; // Set newly added options case "update": const { options } = await browser.storage.sync.get("options"); const newOptions = {}; // Find options not already in storage for (const [ key, val ] of Object.entries(initialOptions)) { if (!options.hasOwnProperty(key)) { newOptions[key] = val; } } // Update storage with default values of new options browser.storage.sync.set({ options: { ...options , ...newOptions } }); break; } }); // Google-hosted API loader script const SENDER_SCRIPT_URL = "https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"; const SENDER_SCRIPT_FRAMEWORK_URL = `${SENDER_SCRIPT_URL}?loadCastFramework=1`; /** * Sender applications load a cast_sender.js script that * functions as a loader for the internal chrome-extension: * hosted script. * * We can redirect this and inject our own script to setup * the API shim. */ browser.webRequest.onBeforeRequest.addListener( async details => { switch (details.url) { case SENDER_SCRIPT_URL: // Content/Page script bridge await browser.tabs.executeScript(details.tabId, { file: "content.js" , frameId: details.frameId , runAt: "document_start" }); return { redirectUrl: browser.runtime.getURL("shim/bundle.js") }; case SENDER_SCRIPT_FRAMEWORK_URL: // TODO: implement cast.framework return { cancel: true }; } } , { urls: [ SENDER_SCRIPT_URL , SENDER_SCRIPT_FRAMEWORK_URL ]} , [ "blocking" ]); // Defines window.chrome for site compatibility browser.contentScripts.register({ allFrames: true , js: [{ file: "contentSetup.js" }] , matches: [ "" ] , runAt: "document_start" }); // YouTube compat shim browser.contentScripts.register({ allFrames: true , js: [{ file: "compat/youtube.js" }] , matches: [ "*://www.youtube.com/*" ] , runAt: "document_start" }); // Screen/Tab mirroring "Cast..." context menu item browser.menus.create({ contexts: [ "browser_action", "page" ] , id: "contextCast" , title: _("context_media_cast") }); //