The My Opera forums have been replaced with forums.opera.com. Please head over there to discuss Opera's products and features
See the new ForumsYou need to be logged in to post in the forums. If you do not have an account, please sign up first.
Identifying the message sending tab
Hi,In the background process of an extension, how do you identify the tab from which an injected script posts a message? In other extension frameworks there are constructs (roughly) such as sender.tab (Chrome) event.target (Safari), or worker.tab (Firefox Jetpack).
Briefly, the aim is to have my extension active in zero or one tab during web browsing, and the activation logic has to be computed in the background process, which keeps track of the single active tab.
I can't find any tab unique event data in message events, but perhaps there is a workaround?
Best,
Claudijo
You can access event.source to communicate with tab that sent a message. So, algorithm can be the following:
- decide whether tab that sent a message should be active
- send activate/deactivate info to tab using event.source.postMessage
- if tab should be active - send to previous active tab deactivate message
- if tab should be active - save it as previous active tab (you save event.source here)
Useful documentation on this subject is here:
http://dev.opera.com/articles/view/opera-extensions-messaging/
http://dev.w3.org/html5/postmsg/
- decide whether tab that sent a message should be active
- send activate/deactivate info to tab using event.source.postMessage
- if tab should be active - send to previous active tab deactivate message
- if tab should be active - save it as previous active tab (you save event.source here)
Useful documentation on this subject is here:
http://dev.opera.com/articles/view/opera-extensions-messaging/
http://dev.w3.org/html5/postmsg/
The only solution I've come up with is to get every tab, then loop through them comparing the tab's port to the message source until you find a match.
Opera 12.15 - Win 8 Pro x64 All my Opera tools -Tab Vault: Save tabs for later -AutoStack: tabs opened from a stack stay there