简体   繁体   中英

detect chrome.tabs event origin source

I am working on chrome extension that deals with tabs. 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. 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

My idea is:

  • define an array in your background script which keeps all the tab id that your extension changed.

  • listen to onUpdated , onCreated , and all other tab events that you want to listen to

  • check if the tab id in that array, if not, then it's not changed by your extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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