簡體   English   中英

Firefox / Chrome Web擴展-嘗試通過內容腳本注入IFrame時出現安全錯誤

[英]Firefox/Chrome Web Extension - Security Error When Trying To Inject IFrame Through Content Script

每當按下“ popup.html”文件中的按鈕時,內容腳本中就會運行以下非常簡單的代碼:

“ inject.js”內部的代碼部分

browser.runtime.onMessage.addListener((message) => {
    console.log("Trying to inject iFrame");
    var iframe = document.createElement("iframe");
    iframe.src = browser.extension.getURL("inject.html");
    document.body.appendChild(iframe);
});

“ inject.html”的內容是:

<!DOCTYPE html>
<html>

<head>
</head>

<body>
    <p>
        Hello. This is a Test.
    </p>
</body>

</html>

但是,運行此代碼時,我在控制台中得到以下輸出(使用“ example.com:作為示例URL”):

嘗試注入iFrame
安全錯誤: http//example.com/上的內容可能無法加載或鏈接到moz-extension://218287b3-46eb-4cf6-a27f-45b9369c0cd9/inject.html。

這是我的“ manifest.json”

{
"manifest_version": 2,
"name": "Summarizer",
"version": "1.0",

"description": "Summarizes webpages",

"permissions": [
    "activeTab",
    "tabs",
    "storage",
    "downloads",
    "*://*.smmry.com/*"
],

"icons":
{
    "48": "icons/border-48.png"
},

"browser_action":
{
    "browser_style": true,
    "default_popup": "popup/choose_length_page.html",
    "default_icon":
    {
        "16": "icons/summarizer-icon-16.png",
        "32": "icons/summarizer-icon-32.png"
    }
}

"web_accessible_resources": [
    "inject.html"
]
}

最后,這是我的擴展程序的頂級文件結構:

Extension_File_Structure

如何解決此安全錯誤?

這不是重復的: 嘗試getUrl圖像時Firefox WebExtension中的安全錯誤,因為我在manifest.json提供了完整路徑

我錯過了一個逗號。 這是manifest.json的相關部分,並帶有逗號:

"browser_action":
{
    "browser_style": true,
    "default_popup": "popup/choose_length_page.html",
    "default_icon":
    {
        "16": "icons/summarizer-icon-16.png",
        "32": "icons/summarizer-icon-32.png"
    }
},

"web_accessible_resources": [
    "inject.html"
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM