Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content Security Policy Issue #93

Open
trungpv1601 opened this issue Sep 14, 2024 · 12 comments
Open

Content Security Policy Issue #93

trungpv1601 opened this issue Sep 14, 2024 · 12 comments

Comments

@trungpv1601
Copy link

Anyone face with this issue in Google Chrome Canary v130

content-script-loader.chunk-1f004067.310380a0.js:7 Refused to load the script 'chrome-extension://xxx/assets/chunk-1f004067.js' because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost:* http://127.0.0.1:*". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
TypeError: Failed to fetch dynamically imported module: chrome-extension://xxx/assets/chunk-1f004067.js

Make sure you use Google Chrome Canary v130

CleanShot 2024-09-14 at 12 02 22@2x

Thank you

@trungpv1601
Copy link
Author

trungpv1601 commented Sep 16, 2024

My solution for build production

remove chrome.runtime.getURL in content script

(function () {
  'use strict';

  (async () => {
    await import("./chunk-b674a675.js");
  })().catch(console.error);

})();

More Info here: crxjs/chrome-extension-tools#918

@masamaru0513
Copy link

masamaru0513 commented Oct 16, 2024

@trungpv1601
Hello.
I was very anxious about this issue, but with the method you suggested,
I was able to get the extension working again without any problems. I appreciate it.

--
It is also necessary to add to web_accessible_resources.

  web_accessible_resources: [
    {
      resources: ['assets/chunk-xxx-.js'],
      matches: ['<all_urls>'],
    },
  ],

@trungpv1601
Copy link
Author

@trungpv1601 Hello. I was very anxious about this issue, but with the method you suggested, I was able to get the extension working again without any problems. I appreciate it.

-- It is also necessary to add to web_accessible_resources.

  web_accessible_resources: [
    {
      resources: ['assets/chunk-xxx-.js'],
      matches: ['<all_urls>'],
    },
  ],

@masamaru0513

you can find the better solution here crxjs/chrome-extension-tools#918 (comment)

remove all "use_dynamic_url" in the manifest.json build

@masamaru0513
Copy link

I might be saying something strange due to my ignorance...
I think the provisional response to this issue is to delete use_dynamic_url and remove chrome.runtime.getURL in the content script.
However, what should I do about the problem where remove chrome.runtime.getURL reappears every time I run npm run dev and update the code?
Does this mean I need to rewrite it each time?

@trungpv1601
Copy link
Author

I might be saying something strange due to my ignorance... I think the provisional response to this issue is to delete use_dynamic_url and remove chrome.runtime.getURL in the content script. However, what should I do about the problem where remove chrome.runtime.getURL reappears every time I run npm run dev and update the code? Does this mean I need to rewrite it each time?

you can follow this ticket: crxjs/chrome-extension-tools#918

they discuss and working on it for dev env

@masamaru0513
Copy link

Thank you. I will observe the discussion for a while. After these issues are fixed, will it be resolved if Mr. Guocaoyi's create-chrome-ext is also fixed? In any case, I really love using this create-chrome-ext, so I would be happy if it can be resolved. Thank you for the quick response @trungpv1601

sakibul-islam added a commit to sakibul-islam/create-chrome-ext that referenced this issue Oct 25, 2024
@slc3a2
Copy link

slc3a2 commented Oct 27, 2024

only for the production environment

My solution: : In the build directory after run npm run build:

in manifest.json: update all items under web_accessible_resources to have use_dynamic_url set to false:

"web_accessible_resources": [
  {
    "use_dynamic_url": false
  },
  {
    "use_dynamic_url": false
  }
],

get more info: github issue #918 and chromium issue

@mordechaim
Copy link

mordechaim commented Oct 28, 2024

Chrome 130 is now GA, which means every single chrome extension is now broken in production.

The solution I use is to manually edit the output manifest.json in the build to mark "use_dynamic_url": false, as @slc3a2 suggested.


EDIT: Updating @crxjs/vite-plugin fixed it for me

npm i @crxjs/[email protected]

@masamaru0513
Copy link

I also updated the version of crxjs itself, and both dev and production are working.

@slc3a2
Copy link

slc3a2 commented Oct 30, 2024

After I installed and run start:

npm i @crxjs/[email protected]
npm run start

i got an error:

failed to load config from /Users/liangqi/www/dimmer/vite.config.ts
error when starting dev server:
file:///Users/liangqi/www/dimmer/node_modules/@crxjs/vite-plugin/dist/index.mjs:14
import { createLogger, version } from 'vite';
                       ^^^^^^^
SyntaxError: Named export 'version' not found. The requested module 'vite' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'vite';
const { createLogger, version } = pkg;

maybe I need to update vite, to which version?

@bcmcq
Copy link

bcmcq commented Oct 31, 2024

@slc3a2 looks like ^3.2.11. I referenced that from the beta 28 release source code (https://github.com/crxjs/chrome-extension-tools/blob/0dac0e38cb8508ef2c861b84fd99ca78d5ef0565/packages/vite-plugin/package.json).

Fixed it for me.

@slc3a2
Copy link

slc3a2 commented Nov 1, 2024

@bcmcq

I installed vite@^3.2.11, and after npm run start, I got an error, seemed to be from nodejs:

Error: Cannot find module 'node:assert'

After this, I updated nodejs from v14.15.3 to v18.12.1 to solve this problem, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants