Dispatch messages from a safari extension popover to the global page -
i have safari extension popover needs communicate global page. content-script using
safari.self.tab.dispatchmessage(name,data);
to accomplish that. popover didn't find way that. know can access methods in global page directly
safari.extension.globalpage.contentwindow
but goal reuse code fragments used in content-scripts. same chrome version of plugin.
is there code little clever proxy emulates
safari.self.tab.dispatchmessage(name,data);
from popover?
to honest it's easier have different code in popover , injected scripts. if want, this:
function dispatchmessage(name, message) { if (safari.self.tab) { safari.self.tab.dispatchmessage(name, message); } else if (safari.extension.globalpage.contentwindow) { safari.extension.globalpage.contentwindow.handlemessage({name: name, message: message}); } }
then use dispatchmessage('foo', 'bar')
in both popover , injected scripts. it's bit hacky though, because message event object has more information on name
, message
, , have ensure handlemessage
function same function assigned message
event listener in global page.
Comments
Post a Comment