Safari extension for macOS: window.focus()

Hello, I have a macOS app that helps navigation through running apps published on the App Store.

I would like to create a Safari extension for macOS that would allow the user to open directly one of the last used tabs. Activate a tab is not a problem following the documentation, but my question is: can I allow the opening of a tab that is not in the frontmost window of the current instance of Safari?

Security policies about window.focus() function are restrictive also for code executed directly in the "background" script of the extension?

P.S. For example, in a Sandbox application you cannot activate directly a window but just a running application as it was left, so I cannot select the interested Safari's window from the macOS app.

Thank you!

Are you trying to make a Safari App Extension or a Safari Web Extension?

Safari Web Extensions have a more fully defined windows and tabs API that might be better suited to what you are trying to do:

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/windows

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs

Thank you for your reply. I was thinking about a Safari Web Extension, but to be honest the important thing is to know that is possible to achieve this result normally restricted to normal Javascript on web pages or an external sandboxed app.

At the same time, seems that an App Extension has more capabilities and it could be included directly in the primary app without downloading it separately. But in this case I find more difficulties in discovering how to achieve this result. What I found on a web search is deprecated: https://developer.apple.com/documentation/safariextensions/safaribrowserwindow

Safari extension for macOS: window.focus()
 
 
Q