folklorelabs / pockest-helper

Pockest Helper is a browser extension/addon that tracks and automatically cares for Street Fighter Pockest Monsters.
12 stars 1 forks source link

Chrome update broke the extension due to dynamically loading the content script #122

Closed techygrrrl closed 1 month ago

techygrrrl commented 1 month ago

The Chrome update broke the extension. Scripts cannot be injected dynamically as easily anymore.

image

There's (at least) 2 ways to work around this:

  1. Use the new UserScripts API
  2. Load the content script as a static asset and not dynamically

Use the new UserScripts API (not recommended)

You can use the userScripts API and mess with the content security policy with configureWorld. This, however, is overkill for this extension since that's more for scripts that need to load dynamically. You don't need to load it dynamically since you're shipping the content script with the extension. This also has the down side of requiring users to turn on Developer Mode but that's not an issue for your extension since it's not published to the store and users have to do that anyways to load the unpacked extension.

Load the content script as a static asset and not dynamically (recommended)

The plugin you're using to bundle the extension is dynamically loading the content script, which is not necessary. This causes the CSP error.

I did this change in the manifest and got the extension working again:

   "version_name": "1.2.4",
   "content_scripts": [
     {
       "js": [
-        "assets/content-script-loader.index.jsx.48ed4cb1.f80d88b0.js"
+        "assets/index.jsx.48ed4cb1.js"
       ],
       "matches": [
         "https://www.streetfighter.com/6/buckler/*minigame*"
       ],
@@ -37,5 +37,5 @@
       ],
       "use_dynamic_url": true
     }
   ]
}

So either you can modify the manifest after the build (possibly the quickest option) or find another way to bundle the extension that doesn't use @crxjs/vite-plugin. I did just check their issues now and it looks like it's a known issue: https://github.com/crxjs/chrome-extension-tools/issues/918

So if you're not a developer and you'd like to fix this and you don't mind poking around in some code:

  1. Open the manifest.json file in a text editor like Notepad or Visual Studio Code
  2. Copy the value that starts with assets/index.jsx—the hash (in my case 48ed4cb1) will be different since I'm on the head of the develop branch. You'll need to copy the line in your manifest and not the one in the diff above.
  3. Paste the path in place of the line that says content-script-loader line
folklorelabs commented 1 month ago

Fix included in v1.2.5; thanks again for all the info above!