SFSafariApplication::dispatchMessage() in xcode 16

We are making Safari extension for MacOS, that uses SFSafariApplication.dispatchMessage() to communicate between native and javascript parts of extension. Until recently everything worked, however after update to xcode 16 I started getting this error:

'dispatchMessage(withName:toExtensionWithIdentifier:userInfo:completionHandler:)' is unavailable in application extensions for macOS: Not available to extensions
'dispatchMessage(withName:toExtensionWithIdentifier:userInfo:completionHandler:)' has been explicitly marked unavailable here (SafariServices.SFSafariApplication)

I looked into documentation, however I did not find any hint of dispatchMessage() being replaced by something else. According to https://developer.apple.com/documentation/safariservices/messaging-between-the-app-and-javascript-in-a-safari-web-extension this is the way communication should be done.

Is it a bug? Or can someone direct me to working alternative of communication?

Answered by Frameworks Engineer in 804150022

The error you're seeing is because dispatchMessage(withName:toExtensionWithIdentifier:userInfo:completionHandler:) has always been unavailable for app extensions, which is now being flagged by the compiler in Xcode 16.

Communication from the extension to JavaScript is handled via context.completeRequest(returningItems:completionHandler:), but only in response to messages initiated from JavaScript. The dispatchMessage method is intended for use by the app itself—not the extension process—to initiate communication when the app is running.

SFSafariApplication::dispatchMessage() in xcode 16
 
 
Q