Chrome扩展程序:如何从后台页面了解选项卡何时完成加载 [英] Chrome extensions : How to know when a tab has finished loading, from the background page

查看:131
本文介绍了Chrome扩展程序:如何从后台页面了解选项卡何时完成加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在后台页面中使用侦听器来了解何时加载选项卡:

I'm using a listener in the background page to know when a tab is loaded:

chrome.tabs.onUpdated.addListener(function (tabId) { })

但是侦听器会被触发两次:页面开始加载时以及页面完成时.是否可以区分这两种情况?

But the listener is fired twice: when the page has started loading, and when the page has finished.Is there a way to differentiate the two cases?

推荐答案

幸运的是找到了解决方案.

Luckily have found the solution.

有一个其他参数,该参数保存状态值:

There is an additional parameter that holds the status value:

chrome.tabs.onUpdated.addListener(function (tabId , info) {
  if (info.status === 'complete') {
    // your code ...
  }
});

状态可以是loadingcomplete.

这篇关于Chrome扩展程序:如何从后台页面了解选项卡何时完成加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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