lapcat / SafariExtensions

Resources for the development of Safari extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FB7869857 - Safari app extension: Provide preloaded JSON to content script at load

lapcat opened this issue · comments

I would love if my Safari app extension could provide preloaded JSON to my content scripts at load time. This would be similar to Safari content blocker rules, which are also preloaded, and are only loaded again if the content blocker extension calls SFContentBlockerManager reloadContentBlockerWithIdentifier. My Safari extension has site-specific preferences. Unfortunately, my content scripts have to make async calls in order to get these preferences. They have to add an event listener for "message", call safari.extension.dispatchMessage, and then wait for the async reply from the app extension. The same thing has to happen on every page load, but the preferences only rarely change, so it's fetching the same data async over and over. Moreover, having only async access to preferences dramatically limits what my content scripts can do, because certain decisions and actions have to be made at page load, before the web site gets a chance to load any of its content. And it also overcomplicates the logic of the content script to make the access to preferences async rather than sync. Having preloaded JSON available to the content script would solve these problems.