onMessage handler for web extension provided iFrame never fires

I'm trying to convert a Safari App Extension to the newer Safari Web Extension API, and having an issue with an injected iFrame we use to protect user data. Inside our provided iFrame which which we source from:
Code Block
safari-web-extension://<ID_HERE>/<HTML_FILE_HERE>

and is externally_connectable via the manifest.json.

Any scripts that run inside the iFrame are able to initiate communication with background scripts with no problem. However, any message initiated from background never registers on any onMessage listener. For example:

Code Block javascript
// iframe.js
// WORKS FINE
browser.runtime.sendMessage({ greeting: "hello" })
.then((response) => {
console.log("Received response: ", response);
});
// NEVER FIRES
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log("Received request: ", request);
});

I'm convinced this is an Apple bug because this same scenario for the App Extensions receives the request from the background scripts no problem. Can anyone prove me otherwise?

Replies

If you could file feedback at https://feedbackassistant.apple.com with a sample extension that reproduces the issue, that would be the most helpful for us.

Thanks for the feedback!
Thank you, bweinstein. I've filed under FB8967592 with a sample demo. Hope that helps.

Hi, I'm having the same problem, any progress so far? Thanks!

Hello, this problem is still present in the current version of Safari. Is there any plan to fix this?

This should be fixed in Safari for iOS 16, Safari on macOS Ventura, and the latest versions of Safari Technology Preview. Please let us know if you're still seeing this issue on any of those!

  • Hey there @bweinstein, circling back on this issue, sorry for the delay, I appreciate your following up on this.

    However, I've run the my test again both via the code sample I uploaded for the feedback ticket, as well as with my company's project. In both cases I can still reproduce this issue. So I'm afraid it's not fixed, at least given my current environment.

    I'm on Ventura running Safari 16.1.

    Please advise!

Add a Comment