首页 > 解决方案 > EvalError:拒绝将字符串评估为 JavaScript,因为 'unsafe-eval' - Chrome 扩展

问题描述

我正在迁移到 manifest v3,我将所有需要的内容安全策略添加到 manifest.json 文件中。但是我收到以下错误:

EvalError:拒绝将字符串评估为 JavaScript,因为 unsafe-eval 不是以下内容安全策略指令中允许的脚本源:script-src self。

在 eval () 在 inboxsdk.js:1177

清单.json:

"content_scripts": [
    {
      "all_frames": false,
      "css": [ "css/content.css", "style.css", "css/buttons.css" ],
      "include_globs": [ "*://mail.google.*/*" ],
      "js": [ "resources/jquery-3.3.1/jquery-3.3.1.min.js", "js/api.js", "js/inpage.js", "js/menus.js", "js/content.js", "js/background.js", "lib/q.js", "js/inboxsdk.js", "js/app.js" ],
      "matches": [ "*://*/*", "<all_urls>" ],
      "run_at": "document_start"
    },
  "manifest_version": 3,
 "content_security_policy": {
    "extension_pages":" object-src 'self'",
    "sandbox": "sandbox allow-scripts; https://apis.google.com https://apis.google.com/js/client.js https://ajax.googleapis.com https://designshack.net/favicon.ico https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js https://aui-cdn.atlassian.com https://netdna.bootstrapcdn.com https://tarruda.github.com  https://cdnjs.cloudflare.com https://ydn-src-2.storage.googleapis.com  https://www.google.com/  ; default-src 'self'; object-src 'self'"
  },

标签: google-chromegoogle-chrome-extensionchrome-extension-manifest-v3

解决方案


请使用以下代码行更新您的“extension_pages”:“object-src 'self'”

"extension_pages":"script-src 'self'; object-src 'self'",


推荐阅读