Safari App Extensions Windows and Tabs API

I am trying to migrate existing safari legacy extension to the new Safari App Extensions standard. Recently I had an issue:

https://forums.developer.apple.com/message/349544#349544

which actually was the same issue as

https://forums.developer.apple.com/message/341054#341054

And it was addressed in Safari Technology Preview 77

https://webkit.org/blog/8658/release-notes-for-safari-technology-preview-77/

Thanks to that I am able to continue working on porting rest of the code.


However the extension I am porting also heavily relies on legacy "The Windows and Tabs API"

https://developer.apple.com/library/archive/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html#//apple_ref/doc/uid/TP40009977-CH17-SW1


More specifically "open", "close", "navigate" events, I use these events to track and identify tabs from which messages are coming from. Using these events I have had created somewhat similar API to that of WebExtension API standard which is crucial to the functionality of the extension.

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


To give an understanding of what kind of functionality I'm trying to achieve I'll try to describe one use case, even though there are more.


1. The user sees a list of URLs in a popup view.

2. Clicking one of these URLs opens it in a new tab of the active window.

3. Opened tab frames send messages requesting information regarding the open request.


Note (After creating a tab and opening URL in it I need to attach additional information to that Tab which will persist until the tab is closed, refresh, or another URL opening shouldn't delete that data)


This is how I used to achieve this functionality with the previous API:

const tabInfoMap = new WeakMap();
const tab = window.safari.application.activeBrowserWindow.openTab();
tabInfoMap.set(tab, "some addinal info which needs to be sent to frames when they are ready");

window.safari.application.addEventListener("message", (event) => {
  const tabInfo = tabInfoMap.get(event.target);

  if (tabInfo) {
      event.target.page.dispatchMessage("message-name", tabInfo);
  }
});

// close event is used to clean up, because otherwise stored data would never be destroyed
// event though it will not be used anymore, which is kind of a memory leak
window.safari.application.addEventListener("close", (event) => {
    tabInfoMap.delete(event.target);
})


I saw some other posts from people that are experiencing other issues regarding "Windows and Tabs API" e.g.

https://forums.developer.apple.com/thread/115540


My guess is that there will be more users and more cases where these APIs are necessary. Is there any plans to implement these APIs before dropping support for old extensions. Or is there any other way to achieve needed functionality?