Javascript 为<;脚本>;带源“;https://localhost/js/test.js”

Javascript 为<;脚本>;带源“;https://localhost/js/test.js”,javascript,firefox,message,content-script,Javascript,Firefox,Message,Content Script,背景脚本: let show_floater = true; chrome.browserAction.onClicked.addListener(function (event) { console.log('clicked'); chrome.tabs.executeScript(null, { file: 'js/content.js', /* my content script */ }, () => { connect

背景脚本:

let show_floater = true;

chrome.browserAction.onClicked.addListener(function (event) {
    console.log('clicked');
    chrome.tabs.executeScript(null, {
        file: 'js/content.js', /* my content script */   }, () => {
            connect(show_floater) //this is where I call my function to establish a connection     
        });
    });
});

function connect(sf) {
    chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
        console.log(show_floater, sf);
        const port = chrome.tabs.connect(tabs[0].id);

        console.log('doing stuff);

        port.postMessage(sf);
    });
}
内容脚本:

let var injected = false;

chrome.runtime.onConnect.addListener((port) => {
    port.onMessage.addListener((show_floater) => {
        if (!show_floater) {
            injected = 0;
            document.querySelector(".beebole_css").remove();
            document.querySelector(".beebole_js").remove();
            document.querySelector(".beebole_container").remove();
            //document.querySelector(".beebole_button").remove();
        }
        else if (!injected) {
            injected = true;

            let link = document.createElement("link");
            link.className = 'beebole_css';
            link.href = "https://localhost/css/test.css";
            link.type = "text/css";
            link.rel = "stylesheet";
            document.querySelector("head").appendChild(link);

            let s = document.createElement("script");
            s.className = 'beebole_js';
            s.src = "https://localhost/js/test.js";
            s.type = 'text/javascript';
            // document.body.appendChild(s);
            document.querySelector('body').appendChild(s);
        }
    });
});
上面的代码在Chrome上运行,但是在Firefox上我得到了这个错误

Loading failed for the <script> with source “https://localhost/js/test.js”.
为具有源的加载失败”https://localhost/js/test.js”.
这是我的舱单

{
    "manifest_version": 2,
    "name": "Counterstring",
    "version": "0.1",
    "description": "simple counterstring generation",
    "content_scripts": [
    {
        "run_at": "document_end",
        "matches": [
            "<all_urls>"
        ],
        "js": [
            "js/content.js"
        ]
    }
    ],
    "content_security_policy": "script-src 'self' https://localhost/js/test.js; object-src 'self'",
    "background": {
        "persistent": true,
        "scripts": [
            "js/background.js"
        ]
    },
    "browser_action": {
        "deafult_icon": "icons/icon16x16.png"
    },
    "permissions": [
        "contextMenus",
        "activeTab",
        "tabs"
    ],
    "icons": {
        "16": "icons/icon16x16.png",
        "48": "icons/icon48x48.png",
        "128": "icons/icon128x128.png"
    }
}
{
“清单版本”:2,
“名称”:“反字符串”,
“版本”:“0.1”,
“说明”:“简单反字符串生成”,
“内容脚本”:[
{
“运行时间”:“文件结束时间”,
“匹配项”:[

“我应该可以通过使用postMessage()来避免这种情况我的理解有缺陷吗?< /P> < P>找到解决方案,问题是我没有授权我的本地主机在Firefox上的SSL证书。< /P> @ ExpJS123我将如何处理它?因为在Chrome上它没有问题,但是在Firefox No. @ ExpJS123上做一些阅读,然后考虑你刚才做的评论。