Can't access Safari Javascript object from bundled HTML file

At this past WWDC, @bweinstein said this:


"Safari now injects the safari javascript object to any frames loaded with content from your extension, meaning those frames can send message to the Safari App Extension and receive messages from it"


Link to video, go to 10:50


However, when I successfully load a bundled html file from the contents of my extension, I am not able to communicate with the safari javascript object to send and recieve messages from my Safari App Extension. I am on testing this on Safari 12.1.2. I am attempting to communicate with the safari javascript object as I would from a content script, ex. `safari.extension.dispatchMessage("Hello World!");`


Is this a bug, can anyone give me some insight here?

Accepted Reply

This should be fixed in the Safari 13 Beta and the beta of macOS Catalina.


It should also be fixed in the latest version of Safari Technology Preview, if that's easier to test with.

Replies

This should be fixed in the Safari 13 Beta and the beta of macOS Catalina.


It should also be fixed in the latest version of Safari Technology Preview, if that's easier to test with.

That's great to hear, Brian. Thank for you the reply.

I've upgraded to Safari 13 and I have a verified it is all working. I am able to send and receive messages to and from my bundled HTML content.


Note, you will communicate with your bundled HTML content in the same way you would a content script.


To send a message from a bundle html page:


safari.extension.dispatchMessage("message_name");


To recieve a message on a bundle html page:


function handleMessage(event) {
     console.log(event);
}
safari.self.addEventListener("message", handleMessage);