/ src / background / contentScriptHMR.ts
contentScriptHMR.ts
 1  import { isFirefox, isForbiddenUrl } from "~/env";
 2  
 3  // Firefox fetch files from cache instead of reloading changes from disk,
 4  // hmr will not work as Chromium based browser
 5  browser.webNavigation.onCommitted.addListener(({ tabId, frameId, url }) => {
 6    // Filter out non main window events.
 7    if (frameId !== 0) return;
 8  
 9    if (isForbiddenUrl(url)) return;
10  
11    // inject the latest scripts
12    browser.tabs
13      .executeScript(tabId, {
14        file: `${isFirefox ? "" : "."}/dist/contentScripts/index.global.js`,
15        runAt: "document_end",
16      })
17      .catch((error) => console.error(error));
18  });