Google chrome extension Chrome页面操作单击不工作

Google chrome extension Chrome页面操作单击不工作,google-chrome-extension,Google Chrome Extension,这是我的manifest.json文件 { "name": "My First Extension", "version": "1.0", "description": "The first extension that I made.", "background_page": "background.html", "page_action": { "default_icon": "icon.png" }, "permissions" : [ "t

这是我的manifest.json文件

{
  "name": "My First Extension",
  "version": "1.0",
  "description": "The first extension that I made.",
  "background_page": "background.html",
  "page_action": 
 {
     "default_icon": "icon.png"
 },
  "permissions" : [
    "tabs"
  ]
}
这是background.html

<html>
  <head>
    <script>
      // Called when the url of a tab changes.
      function checkForValidUrl(tabId, changeInfo, tab) {
        // If the letter 'page' is found in the tab's URL...
        if (tab.url.indexOf('google') > -1) {
          // ... show the page action.
          chrome.pageAction.show(tabId);
        }
      };

      // Listen for any changes to the URL of any tab.
      chrome.tabs.onUpdated.addListener(checkForValidUrl);

   chrome.pageAction.onClicked.addListener(function(tab)
    {
           tab.url = 'www.bing.com';
                             console.log('I am clicked');
    }
            );


    </script>
  </head>
</html>

//当选项卡的url更改时调用。
函数checkForValidUrl(选项卡ID、更改信息、选项卡){
//如果在选项卡的URL中找到字母“page”。。。
if(tab.url.indexOf('google')>-1){
//…显示页面操作。
chrome.pageAction.show(tabId);
}
};
//侦听对任何选项卡的URL的任何更改。
chrome.tabs.onUpdated.addListener(checkforvalidul);
chrome.pageAction.onClicked.addListener(函数(选项卡)
{
tab.url='www.bing.com';
log(“我被点击了”);
}
);
当我点击页面操作图标时,我想将页面重定向到Bing.com,但这个点击事件对我不起作用


谢谢

您尝试过使用javascripts window.location函数吗?e、 g:

window.location=”http://www.bing.com";


如果这不起作用,那么可能是您的事件侦听器出了问题。

如果您想重定向需要使用的选项卡:

chrome.tabs.update(tab.id, {url: "http://www.bing.com"});
您还需要检查页面的状态,因为每个页面将执行两次
checkforvalidul

function checkForValidUrl(tabId, changeInfo, tab) {
    if(changeInfo.status === "loading") {
        //...
    }
});

您是否检查了控制台的错误?如何调试。无法查看“检查”菜单项,其已禁用。请思考,事件侦听器未被调用。我试图在控制台中查看,但也没有调用“我被单击”。这不起作用。我相信没有调用事件侦听器。也许我错过了什么,但不知道什么。