You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue: SharedWorker callbacks become unavailable after tabs go idle (multi-tab scenario)
Description
When using a SharedWorker to share a single PubNub connection across multiple browser tabs, we are encountering an issue where callbacks (MessagePort communication) become unavailable after tabs remain idle or backgrounded for some time.
This happens especially when:
Multiple tabs are connected to the same SharedWorker
Tabs go idle / backgrounded for a while
A PubNub event is received after the idle period
At that point, the SharedWorker attempts to notify all connected tabs, but some ports throw errors indicating that the callback or message port is no longer available.
Expected Behavior
SharedWorker should be able to safely broadcast PubNub events to all active tabs.
Inactive or backgrounded tabs should not cause errors when PubNub events arrive.
Message ports that are no longer valid should be safely ignored or cleaned up.
Actual Behavior
After tabs remain idle/backgrounded, PubNub events trigger errors such as:
callback not available
failed postMessage / port is closed
This breaks event delivery and sometimes impacts other active tabs.
Environment
Angular - v20.2
Pubnub - 9.7.0 & same version worker file
Browser: Chrome / Chromium-based browsers
Steps to Reproduce
Open multiple tabs of the same application
All tabs connect to a SharedWorker
SharedWorker initializes a single PubNub connection
Leave tabs idle or backgrounded for some time
Trigger a PubNub message/event
Observe errors when the SharedWorker attempts to postMessage to inactive tabs
Questions
Are there recommended best practices from PubNub for using the JS SDK inside a SharedWorker?
Is there an officially supported pattern for multi-tab PubNub usage (SharedWorker vs ServiceWorker vs per-tab connection)?
Are there SDK-level safeguards or lifecycle hooks that can help detect inactive consumers?
Is there any special benefits of using or we can just remove that completely?
Possible Workarounds (Current)
after removing SharedWorker it works fine, // subscriptionWorkerUrl: "/pubnub.worker.9.7.0.min.js"
Any guidance or examples from the PubNub team would be greatly appreciated.
Issue: SharedWorker callbacks become unavailable after tabs go idle (multi-tab scenario)
Description
When using a
SharedWorkerto share a single PubNub connection across multiple browser tabs, we are encountering an issue where callbacks (MessagePort communication) become unavailable after tabs remain idle or backgrounded for some time.This happens especially when:
At that point, the SharedWorker attempts to notify all connected tabs, but some ports throw errors indicating that the callback or message port is no longer available.
Expected Behavior
Actual Behavior
Environment
Steps to Reproduce
SharedWorkerQuestions
SharedWorker?Possible Workarounds (Current)
Any guidance or examples from the PubNub team would be greatly appreciated.