Снимите флажок runtime.lastError при запуске tabs.executeScript - PullRequest
0 голосов
/ 12 октября 2018

Почему скрипт My Extension продолжает работать в расширении chrome: // и выдает следующую ошибку: «Не проверено runtime.lastError при запуске tabs.executeScript: Невозможно получить доступ к chrome: // URL»

Мой background.jsкто выдает ошибку

chrome.runtime.onInstalled.addListener(function(){
    chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
        chrome.declarativeContent.onPageChanged.addRules([{
            conditions: [new chrome.declarativeContent.PageStateMatcher({
              pageUrl: {hostContains: 'facebook.com'},
            })
            ],
            actions: [new chrome.declarativeContent.ShowPageAction()]
        }]);
    });
});

var BgSet = '';
var setting = 'document.body.style.backgroundSize = "100% auto"; document.body.style.backgroundPosition = "center top"; document.body.style.backgroundRepeat = "repeat-y";'; //default

chrome.tabs.onUpdated.addListener(function(tabID, changeInfo, tab){
    if(tab["status"] == "complete" && tab["url"] ){
        if(localStorage["BackgroundColor"] != null || localStorage["BackgroundColor"] != ''){
            BgSet += 'document.body.style.backgroundColor = "' + localStorage["BackgroundColor"] + '"; ';
        }
        if(localStorage["BackgroundImage"] != null || localStorage["BackgroundImage"] != ''){
            BgSet += 'document.body.style.backgroundImage = "url(' + localStorage["BackgroundImage"] + ')"; ';
        }
        if (localStorage["Setting"] == 'CenterNo') {
            var setting = 'document.body.style.backgroundSize = "100% auto"; document.body.style.backgroundPosition = "center"; document.body.style.backgroundRepeat = "no-repeat"; document.body.style.backgroundAttachment = "fixed";';
        }
        else if (localStorage["Setting"] == 'CenterWith') {
            var setting = 'document.body.style.backgroundSize = "100% auto"; document.body.style.backgroundPosition = "center top"; document.body.style.backgroundRepeat = "repeat-y"; document.body.style.backgroundAttachment = "";';
        }
        if(BgSet!=""){
            chrome.tabs.query({active:true, currentWindow:true}, function(tabs){
            chrome.tabs.executeScript(
                tabs[0].id,
                {code:  BgSet+
                        'if(document.getElementById("contentCol")!=null)document.getElementById("contentCol").style.backgroundColor = "transparent";'+
                        'if(document.getElementById("pagelet_timeline_recent")!=null)document.getElementById("pagelet_timeline_recent").style.backgroundColor = "transparent";'+
                        setting});
            });
        }
    }
});

Мой манифест.JSON

{
    "name" : "Facebook Beauty",
    "description" : "Editing Your Facebook",
    "permissions" : [
        "activeTab",
        "declarativeContent",
        "storage",
        "unlimitedStorage",
        "http://*.facebook.com/*",
        "https://*.facebook.com/*"
    ],
    "version" : "1.0",
    "background":{
        "scripts": ["background.js"],
        "persistent": true
    },
    "page_action":{
        "default_popup" : "popup.html",
        "default_icon" :{
            "16" : "images/get_started16.png",
            "32" : "images/get_started32.png",
            "48" : "images/get_started48.png",
            "128" : "images/get_started128.png"
        }
    },
    "content_scripts": [
        {
        "matches": [
            "http://*.facebook.com/*",
            "https://*.facebook.com/*"
            ],
        "js": ["content.js"],
        "run_at": "document_end"
        }
    ], 
    "icons" :{
        "16" : "images/get_started16.png",
        "32" : "images/get_started32.png",
        "48" : "images/get_started48.png",
        "128" : "images/get_started128.png"
    },
    "manifest_version" : 2
}

Почему мое расширение продолжает вводить background.js в chrome: // я уже использую декларативное содержимое только для facebook.com?я что-то скучаю?Мой Background JS уже не работает на другом веб-сайте, кроме facebook.com и с ошибкой в ​​chrome: //

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...