Post

Replies

Boosts

Views

Activity

Reply to Safari nativeMessaging with non-persistent background page
SFSafariApplication.dispatchMessage() only guarantees that the native Swift/Obj-C extension process ( SafariWebExtensionHandler / SafariExtensionHandler ) is running. The background script is not woken up if it's already been suspended by the browser. And as far as your companion app is concerned, the message was successful because SafariWebExtensionHandler received it successfully. But the background script didn't receive it. What I've had to do in order to try to work around these limitations is to use a "keep alive" timer within my background script, such as: let keepAliveInterval; function startKeepAlive() { if (keepAliveInterval) return; keepAliveInterval = setInterval(() => { // Simple API call to keep background script alive chrome.runtime.getPlatformInfo(); console.debug('Keep-alive ping'); // eslint-disable-next-line no-magic-numbers }, 25000); // Every 25 seconds } // Start keep-alive system immediately at top level startKeepAlive(); This seems to help keep the background script alive. It's my understanding that Safari on macOS is supposed to support persistent background scripts. See this: https://developer.apple.com/documentation/safariservices/optimizing-your-web-extension-for-safari Which states: Consider making your background page nonpersistent in macOS when it’s primarily event-driven and responds to user interactions. In iOS, you must make your background page nonpersistent. But it doesnt seem to work for me. I get this error: Invalid persistent manifest entry. A manifest_version greater-than or equal to 3 must be non-persistent.
Topic: Safari & Web SubTopic: General Tags:
3w