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 Forums

Identifying the message sending tab

Forums » General Opera topics » Opera extensions

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

27. November 2011, 11:55:43

claudijo

Posts: 3

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

27. November 2011, 18:35:45

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/

27. June 2012, 18:14:48

BS-Harou

Posts: 232

And what should I do if I need to determine the tab that send the message to e.g. focuse it?

29. June 2012, 13:54:14

spadija

Posts: 1643

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.

Forums » General Opera topics » Opera extensions