简体   繁体   English

检测 chrome.tabs 事件源

[英]detect chrome.tabs event origin source

I am working on chrome extension that deals with tabs.我正在研究处理标签的 chrome 扩展。 The extension allows to open and close tabs.该扩展程序允许打开和关闭选项卡。
I also need to know when a tab had opened and closed outside of my extension, so I listen to tabs.onClose and tabs.onCreate events.我还需要知道一个选项卡何时在我的扩展程序之外打开和关闭,因此我会监听 tabs.onClose 和 tabs.onCreate 事件。 My question is how can I determine easily whether an open tab action happened in my extension or outside of it?我的问题是如何轻松确定打开的选项卡操作是发生在我的扩展程序中还是外部?

Basically you can not do this easily, because tab event does not have something like event resource to let you track who make changes to the tabs基本上你不能轻易做到这一点,因为标签事件没有类似event resource东西来让你跟踪谁对标签进行了更改

My idea is:我的想法是:

  • define an array in your background script which keeps all the tab id that your extension changed.在您的后台脚本中定义一个数组,该数组保留您的扩展程序更改的所有选项卡 ID。

  • listen to onUpdated , onCreated , and all other tab events that you want to listen to收听onUpdatedonCreated以及您想收听的所有其他选项卡事件

  • check if the tab id in that array, if not, then it's not changed by your extension.检查该数组中的选项卡 ID,如果没有,则它不会被您的扩展程序更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM