阻止chrome在我的扩展程序中启动时加载所有选项卡?

时间:2010-12-13 12:18:41

标签: javascript google-chrome google-chrome-extension

我正在尝试阻止Chrome启动时加载所有标签。然后我 我只想加载我点击的标签。

我可以使用

中的内容脚本来完成此操作

的manifest.json。

{
 "name": "blah",
 "version": "1.0",
 "background_page": "background.html",
 "content_scripts": [
   {
    "matches": ["http:// */*"],
    "js": ["stop.js"],
    "run_at": "document_start"
   }
 ] ,
 "permissions": [
   "tabs", "http://*/*"
 ]
}

stop.js只包含一行

window.stop();

现在这不太理想,因为作为内容脚本,它会停止加载 每次,包括当我点击标签时。

所以,我尝试在没有内容脚本的情况下在background.html中进行,但是 我无法让它发挥作用:

background.html

<!doctype html>
<html>
<script>

       chrome.tabs.getAllInWindow(null, function stopTabs(tabs) {
         for (var i in tabs) {
               var tab = tabs[i];
               //alert(tab.url);
               var stopLoading = {'code': 'window.stop();alert("stopped");'}; //alerts work here, but window.stop doesn't?!!
               chrome.tabs.executeScript(tab.id, stopLoading);
         }
       });

</script>
</html>

我该怎么做?加载点击的标签似乎很简单,但我需要先这样做。

1 个答案:

答案 0 :(得分:2)

看起来这个问题与this bug report有关,如果你加注它可能会更快修复。

相关问题