SFSafariApplication.dispatchMessage() switches Safari to foreground?

I'm developing a Safari web extension for macOS that calls SFSafariApplication.dispatchMessage() (Swift) to communicate with background.js and the popup. However, I noticed that the method forcefully switches Safari to foreground. It seems it happens after calling browser.runtime.sendNativeMessage(''); in JavaScript.

Is there a way to avoid that behavior? Or perhaps I'm misunderstanding something?

This is a sample project and its video (Safari is switched to foreground every 3 seconds.):

  • Sample project: https://www.dropbox.com/s/vs7h128ef1ji34q/ForcefulForegroundIssuePlayground.zip?dl=0
  • Video: https://www.dropbox.com/s/7pjbh1rihnh068l/Screen%20Recording%202021-12-23%20at%205.42.44%20pm.mov?dl=0

By the way, I already submitted a feedback for this as FB9804951 about 2 weeks ago but no response from Apple so far and I don't know if Apple will take any action for that or not even after the new year so I decided to ask here as well.

Replies

Thanks for filing this!

What are you trying to use this messaging for so that you don't want Safari to come to the foreground?

  • Thanks bweinstein. My Web extension shows the same content with the app and the user can edit that content in the app. When the user edits it, the app tells the extension so via DistributedNotificationCenter and then the extension applies the changes to background.js and the popup. However, because of this issue, everytime when the user edits, Safari is switched to foreground. I find it annoying when the user wants to stay at the app to keep editing. I don't say the current behavior is a bug, but at least I'd like to have a workaround to avoid this behavior. By the way, you can check the details from "Why this is a problem?" section in FB9804951. Please let me know if I can help you solve this issue 🙂

Add a Comment