Google chrome extension chrome扩展不适用于安全站点https

Google chrome extension chrome扩展不适用于安全站点https,google-chrome-extension,Google Chrome Extension,我已经编写了一个chrome扩展,但它似乎不适用于https站点。它当前是一个将脚本注入页面的后台页面。它运行jquery和一些库。到目前为止,我发现要做到这一点,唯一的方法是运行一个后台页面,并使用chrome.tabs.executescript。如果有人知道更好的方法,那也会有帮助 我已经为http和https站点添加了权限,所以我认为这就足够了。请找个人帮忙,谢谢 舱单: { "name": "My First Extension", "version": "1.0",

我已经编写了一个chrome扩展,但它似乎不适用于https站点。它当前是一个将脚本注入页面的后台页面。它运行jquery和一些库。到目前为止,我发现要做到这一点,唯一的方法是运行一个后台页面,并使用chrome.tabs.executescript。如果有人知道更好的方法,那也会有帮助

我已经为http和https站点添加了权限,所以我认为这就足够了。请找个人帮忙,谢谢

舱单:

 {
  "name": "My First Extension",  
  "version": "1.0",  
  "description": "The first extension that I made.",  
  "background_page": "popup.html",  
  "permissions": ["tabs", "http://*/*", "https://*/*"]  
 }  
popup.html

<script type="text/javascript">  

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab)  
{  
    if(changeInfo.status == "loading")  
    {  
        chrome.tabs.insertCSS(null, { file: "jquery-ui-1.8.10.custom.css" }, null);  
        chrome.tabs.executeScript(null, { file: "jquery.min.js" }, null);  
        chrome.tabs.executeScript(null, { file: "jquery-ui-1.8.10.custom.min.js" }, null);  
        chrome.tabs.executeScript(null, { file: "jquery.hotkeys-0.7.9.min.js" }, null);  
        chrome.tabs.executeScript(null, { file: "custom.js" }, null);  
    }  
})  

</script>  

chrome.tabs.onUpdate.addListener(函数(tabId、changeInfo、tab)
{  
如果(changeInfo.status==“正在加载”)
{  
chrome.tabs.insertCSS(null,{file:“jquery-ui-1.8.10.custom.css”},null);
executeScript(null,{file:“jquery.min.js”},null);
executeScript(null,{file:“jquery-ui-1.8.10.custom.min.js”},null);
executeScript(null,{file:“jquery.hotkeys-0.7.9.min.js”},null);
executeScript(null,{file:“custom.js”},null);
}  
})  
custom.js文件是我进行编码的地方

谢谢

尝试将“conent_脚本”添加到manifest.json:

"content_scripts": [
    {
            "matches": ["http://*/*", "https://*/*"],
            "css": ["empty.css"]
    }]
您必须指定“css”或“文件”。在我的插件中,脚本是动态加载的,所以我只使用一个伪css文件


另请参见:

可能依赖项存在问题。对executeScript的所有调用都是异步的。因此,当您开始注入jquery热键时,不能假设jquery被注入。您最好使用以下内容:

var runScripts = function(tabId, scripts, cb) {
        var current = scripts.shift();
        if (current) {
            chrome.tabs.executeScript(tabId, {file: current}, function(a) {
                console.log("Finished running script:", current);
                runScripts(tabId, scripts, cb);
            });
        } else {
            cb();
        }
    };

chrome.tabs.insertCSS(null, {file: "jquery-ui-1.8.10.custom.css"}, function () {
    runScripts( null, ["jquery.min.js", "jquery-ui-1.8.10.custom.min.js", "jquery.hotkeys-0.7.9.min.js", "custom.js"], function() {}); 
});

我认为谷歌限制你这么做。我试过了,很遗憾,这不起作用。也许Blender是对的,也许谷歌限制它在https网站上运行。这是一个遗憾,因为我写的扩展是一个弹出窗口,在一个热键上说crtl+?尚未决定,将显示一个弹出窗口,您可以在其中键入新的url,按enter键,它会将页面更改为该网站。它适用于不安全的站点。这将是真正有帮助的时候,你做全屏(F11)。我希望在完成后发布它。我只是检查了弹出窗口并在控制台中执行了
chrome.tabs.executeScript(null,{code:“alert(document.title);”},null)
。这对https站点有效。您是否尝试过从调试器窗口运行它?异常消息大部分时间都很有用。我刚刚用扩展名再次测试。看起来我可以注入简单的脚本。即
调试器工作。但是,如果我注入一组更复杂的脚本(jquery、jquery ui和一些custom.js,其中显示一个弹出对话框),它就会自动失败。没有错误,但也没有发生任何事情。嗨,是的,我的也在Facebook上工作。你能试试你的谷歌邮箱吗?e、 我的那页不行,我没有gmail帐号。不过,它在注册页面上起作用。很可能脚本注入工作正常。也许页面的JavaScript可以防止某些事件冒泡到处理程序中。就像我的对话不适用。您是否尝试添加一些
警报('foo')
custom.js
?我还没有尝试过,但我认为答案是您之前提到的,即当站点很复杂并且包含框架集时。我的扩展确实可以使用https,只是google mail在站点中有框架。我也这么认为。我假设jquery热键插件/your custom.js不适用于框架集。我必须承认,我不是很精通框架,因为我总是试图避免它们。无论如何,我认为您必须将处理程序附加到$(“body”)的每个帧instad。