7

I am porting a chrome/opera extension to safari. It shows a popover with some data relative to the page. So it needs to communicate with the injected script. I figured out how to communicate between the injected script and background page and popover and background page. But the popover's event listener is not triggered, the popover sends message to injected script and the return message is not received. Maybe I set it for the wrong window object? Or there is a bug in Safari's popover implementation? Thank you.

Here is the code.

In the popover:

safari.self.addEventListener("message", (function(theMessageEvent){
safari.extension.globalPage.contentWindow.console.log("popover message");
//this is the listener that is not called
}));

safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("get");
//this works and sends message to injected script

in the injected script:

safari.self.addEventListener("message", (function(theMessageEvent){
if(theMessageEvent.name=="get"){
theMessageEvent.target.tab.dispatchMessage("setpopover");
//this sends the message back, maybe the target.tab should be changed to something else?

} }

EDIT: I found one solution: the popover send message to the injected script, the injected script sends reply to the background page, and the background page directly calls functions from script in the popover using safari.extension.popovers[0].contentWindow.somefunction();

0 Answers0