crxjs / chrome-extension-tools

Bundling Chrome Extensions can be pretty complex. It doesn't have to be.
https://crxjs.dev/vite-plugin
2.95k stars 189 forks source link

Windows 11 web_accessible_resources output is invalid #265

Open Aidurber opened 2 years ago

Aidurber commented 2 years ago

Build tool

Rollup

Where do you see the problem?

Describe the bug

I built my extension on macOS and it worked fine, I came onto my Windows 11 PC to do some additional work and the extension didn't load. I took a look at other windows related issues in the repo but I think this might be different (apologies if I missed one and this is a dupe).

I did manage to find a work around by specifying the web_accessible_resources myself, I think the problem is the added backslashes. After adding the web resources myself and building this is the output manifest.json (note the backslashes):


 "web_accessible_resources": [
    // The one I manualled added
    {
      "resources": [
        "content/subclass/subclass.js"
      ],
      "matches": [
        "https://rpgbot.net/*"
      ]
    },
    // Added by this plugin
    {
      "resources": [
        "chunks\\*-*.js",
        "content\\subclass\\subclass.js"
      ],
      "matches": [
        "https://rpgbot.net/*"
      ]
    }
  ],

Reproduction

  1. On a Windows OS
  2. Clone my extension: https://github.com/Aidurber/rpgbot-buddy
  3. Install dependencies
  4. Run yarn dev
  5. Go to https://rpgbot.net/dnd5/characters/classes/cleric/subclasses/ (observe the screenshot in my linked repo, it should add a sidebar under the search)
  6. Inspect the console
  7. Observe the comment
  8. Try the workaround provided above
  9. Reload
  10. Extension should load

Logs

Denying load of chrome-extension://iciinnijjkdglbnmoiomknallfoagmkb/content/subclass/subclass.js. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.

rpgbot.net/:1 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: chrome-extension://iciinnijjkdglbnmoiomknallfoagmkb/content/subclass/subclass.js

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
    Memory: 18.59 GB / 31.93 GB
  Binaries:
    Node: 17.4.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.3.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (99.0.1150.52)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    rollup: ^2.56.3 => 2.70.1
    rollup-plugin-chrome-extension: ^3.6.7 => 3.6.7

Severity

annoyance

nerblock commented 2 years ago

I just realized my issue #293 is a duplicate of this one.