iT邦幫忙

1

google extension 要如何開啟外部網站?

  • 分享至 

  • xImage

我想在按鈕被點擊時打開google的網站,但是出現報錯,請問是我的做法不對嗎?
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.

這是manifest.json

{
    "name": "nhentai_guard",
    "description": "it help you filter the tags you don't like before you see it",
    "version": "1",
    "manifest_version": 3,
    "permissions": [
      "storage",
      "activeTab",
      "scripting",
      "tabs",
      "cookies"
    ],
    "host_permissions": [
      "<all_urls>"
    ],
    "action": {
      "default_popup": "/popup/popup.html",
      "default_title": "nhentai_guard",
      "default_icon": {
        "16": "icon.jpg",
        "24": "icon.jpg",
        "32": "icon.jpg"
      }
    },
    "icons": {
        "16": "icon.jpg",
        "24": "icon.jpg",
        "32": "icon.jpg"
    }
  }

這是js

function click(){
    var input = document.getElementById("text_box");
    chrome.tabs.create({ url: "google.com" });
}
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1

您的網頁有CSP規範。
所以不能用JS隨便去生成新的元件。

所有生成的元件都要透過 hash 的宣告來處理。
詳細請先查看CSP規範的應用。

好的,這看起來是個很深的坑…
我會試試看,謝謝你。

我要發表回答

立即登入回答