chrome.tabs.onupdated.addlistener不适用于缓存页面 [英] chrome.tabs.onupdated.addlistener doesn't work on cached pages

查看:190
本文介绍了chrome.tabs.onupdated.addlistener不适用于缓存页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab){
if(tab.url.indexOf('http')=='0' &&; changeInfo.status =='complete'){
alert(JSON.stringify(changeInfo));
}
});

我有这样的background.js,它几乎可以工作在%99但不是%100

无论何时我重新启动浏览器并在浏览器加载缓存中的所有内容时输入一个已访问的网页,它都不会触发此chrome.tabs事件



但有趣的部分是,当我从拨号速度点击相同的网站时,它不会从缓存中加载并调用选项卡。 action

解决方案

根据 https://developer.chrome.com/extensions/webNavigation


并非所有的导航标签页都对应实际的标签页在Chrome的用户界面中,
例如是预先呈现的标签。这些选项卡不能通过选项卡API访问
,也不能通过
webNavigation.getFrame或webNavigation.getAllFrames请求有关它们的信息。一旦这样一个标签
被交换,一个onTabReplaced事件被触发,并且它们变成
可以通过这些API访问。



如果通过Chrome即时或即时页面触发了导航,则会将
完全加载的页面换成当前标签。在这种情况下,
onTabReplaced事件被触发。


尝试使用

  chrome.webNavigation.onTabReplaced.addListener(function(details){
chrome.tabs.get(details.tabId,function(tab){
console。 log(tab.url);
}
}

注意:您需要扩展程序清单中的webNavigation权限:

  {
name:My extension,
...
permissions:[
webNavigation

...
}


chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
    if (tab.url.indexOf('http') == '0' && changeInfo.status == 'complete') {
        alert(JSON.stringify(changeInfo));
    }
});

i have such background.js it nearly works always %99 but not %100

whenever i restart my browser and enter an already accessed web page when browser loads all contents from cache it doesn't fire this chrome.tabs event

but the interesting part is when i click same website from dial speed it doesn't load from cache and calls the "tabs." action

解决方案

According to https://developer.chrome.com/extensions/webNavigation

Not all navigating tabs correspond to actual tabs in Chrome's UI, e.g., a tab that is being pre-rendered. Such tabs are not accessible via the tabs API nor can you request information about them via webNavigation.getFrame or webNavigation.getAllFrames. Once such a tab is swapped in, an onTabReplaced event is fired and they become accessible via these APIs.

and

If a navigation was triggered via Chrome Instant or Instant Pages, a completely loaded page is swapped into the current tab. In that case, an onTabReplaced event is fired.

Try using the chrome.webNavigation.onTabReplaced event to catch this:

chrome.webNavigation.onTabReplaced.addListener(function (details) {
   chrome.tabs.get(details.tabId, function(tab) {
       console.log(tab.url);
   }
}

Note: You'll need the "webNavigation" permission in the extension manifest:

{
    "name": "My extension",
    ...
    "permissions": [
      "webNavigation"
    ],
    ...
  }

这篇关于chrome.tabs.onupdated.addlistener不适用于缓存页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆