Chrome扩展程序标签上的onUpdated事件 [英] Chrome extension tabs onUpdated event

查看:184
本文介绍了Chrome扩展程序标签上的onUpdated事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个chrome扩展程序,该扩展程序在每次打开新标签页并加载页面时都会得到通知,为此,我正在使用chrome.tabs.onUpdated事件.

I am building a chrome extension that should get notified every time a new tab has opened and load page, and for that purpose I'am using chrome.tabs.onUpdated event.

问题是,如果在某个域(具有src)上托管的页面/标签上插入了iframe,则会触发onUpdated事件.有没有办法将这些实际"标签加载事件与为iframe加载触发的事件区分开来?

The problem is that in case an iframe is inserted on that page/tab that is hosted on some domain(has src), onUpdated event is trigered. Is there a way to differentiate these events for "real" tab load from those triggered for iframe load?

推荐答案

tabs.onUpdated在状态在loadingcomplete之间变化时触发.大概是,插入iframe会使标签页再次变为loading状态.

tabs.onUpdated triggers when state changes between loading to complete. Presumably, inserting an iframe puts the tab to loading state again.

您可以查看是否在onUpdated侦听器中定义了details.url-如果未定义,则您知道文档的URL并未更改.

You could see if details.url is defined in onUpdated listener - if not, you know that the document's URL did not change.

也许您应该出于目的使用 webNavigation API .在那里,您会得到一个TransitionQualifier,可用于过滤子帧导航.

Perhaps you should use webNavigation API instead for your purpose. There, you get a TransitionQualifier that you can use to filter out subframe navigation.

这篇关于Chrome扩展程序标签上的onUpdated事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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