実現したいこと
Chrome拡張機能の設定画面にvue.jsを取り入れようと思い、CDNを読み込もうとしたところエラーが発生し、vueが使用できませんでした。
前提
manifest.json
1{ 2 "name": "拡張機能テスト", 3 "description": "説明文", 4 "version": "0.1", 5 "manifest_version": 3, 6 "action": { ... }, 7 "permissions": [ 8 "storage", "tabs", "activeTab", "scripting" 9 ], 10 "web_accessible_resources": [{ ... }], 11 "icons": { ... }, 12 "content_scripts": [{ ... }], 13 "background": { ... }, 14 "options_page": "options.html" 15}
コンソールに出力されたエラー
Refused to load the script 'https://unpkg.com/vue@3/dist/vue.global.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
Refused to load the script 'https://unpkg.com/vue@3/dist/vue.global.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.
options.js:627 Uncaught ReferenceError: Vue is not defined
該当のソースコード
options.html
html
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 5 <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-eval'"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <link rel="stylesheet" href="css/style.css"> 8 <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> 9 10 <title>設定画面</title> 11</head> 12<body> 13 <div id="app">{{ username }}</div> 14 <script src="js/options.js"></script> 15</body> 16</html>
javascript
1const app = Vue.createApp({ 2 data() { 3 return { 4 username: 'なまえ' 5 } 6 }, 7}).mount('#app')
試したこと
<meta http-equiv="Content-Security-Policy" content="〜〜'">
を色々試したり、vue.global.js
をローカルファイル化したりもしましたが、全てダメでした。
補足情報
- Chrome拡張機能 manifest version 3
- Chrome バージョン 110

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/03/16 18:16