Forwarding/processing of messages in the extensions Opera 11

0 like 0 dislike
5 views
After reading the Extension for Opera: messaging decided to check.

Background script (index.html):
<!doctype html>window.addEventListener('load', function(){var button = opera.contexts.toolbar.createItem({ title: 'Send message', icon: 'icons/message.png' })button.addEventListener('click', function(event) {var tab = opera.extension.tabs.getFocused();if (tab)tab.postMessage({}); // можно попробовать и opera.extension.broadcastMessage({});}, false);opera.contexts.toolbar.addItem(button);}, false);


Valley script:
(function () { var storedLocation = "; if (opera.extension !== undefined) { opera.extension.onmessage = function(event){ opera.postError('got message:' + storedLocation); }; } window.opera.addEventListener("BeforeEvent.DOMContentLoaded", function (event) { storedLocation = window.location.href; opera.postError('loaded:' + storedLocation); }, false); })() 


The first thing I noticed processor BeforeEvent.DOMContentLoaded when opening new pages often fulfills more than once.

image

Clearly, there is a iframe with ads.

Okay, but if we click the button, then... the Message gets a background script is, but I would like another.

image

It is clear that the use to send the broadcastMessage() "delivers" the message to the background script of the main page, but to get it, and scripts from other tabs.

image

How to solve the problem of delivering messages to a script on active tab "basic" page?
by | 5 views

2 Answers

0 like 0 dislike
It's very confusing. Before you subscribe to an event BeforeEvent.DOMContentLoaded, check that the script is not in an iframe.
\r
if (window==window.top) { this is not an iframe }
by
0 like 0 dislike
Thanks, but it's not quite right.
\r
The problem is that when I send a message to the active tab, then it (the 99%) gets the background script of a frame of the main page as I would like.
\r
I first thought it was because the frame script is executed later and that it sets your callback. But using broadcastMessage() shows that fulfill both of the handler.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Mar 20, 2019 by ZoomLS
0 like 0 dislike
1 answer
asked Mar 28, 2019 by Serzhenko
110,608 questions
257,186 answers
0 comments
28,667 users