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?
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!

onMessage handler for web extension provided iFrame never fires
 
 
Q