Skip to content

fix: guard SharedWorker reference on runtimes without the global#11

Merged
enzomonjardin merged 1 commit into
masterfrom
tomasz/guard-sharedworker-reference
May 11, 2026
Merged

fix: guard SharedWorker reference on runtimes without the global#11
enzomonjardin merged 1 commit into
masterfrom
tomasz/guard-sharedworker-reference

Conversation

@baransu
Copy link
Copy Markdown

@baransu baransu commented May 11, 2026

Summary

SharedWorker is not defined on mobile Safari, in-app WebViews, and hardened browser modes. The bare guest instanceof SharedWorker checks in host.connect() (lines 53 and 61 of src/host.ts) throw ReferenceError on those runtimes — before we even reach the iframe-target codepath, which is what most consumers actually need.

Adds an isSharedWorker(guest) helper that gates the instanceof check with typeof SharedWorker !== "undefined", mirroring the existing isWorkerLike pattern for Worker. Uses it at both host.ts call sites.

Test plan

  • npm run build — clean
  • npm test — all green, including 2 new regression tests: isSharedWorker returns false without throwing when SharedWorker is undefined; detects instances when the global is present

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@baransu baransu self-assigned this May 11, 2026
@baransu baransu requested a review from enzomonjardin May 11, 2026 10:51
`SharedWorker` is not defined on mobile Safari, in-app WebViews, and
hardened browser modes. The bare `guest instanceof SharedWorker` checks
in `host.connect()` throw `ReferenceError` on those runtimes before we
even reach the iframe-target codepath, which is what most consumers
actually need.

Adds an `isSharedWorker(guest)` helper that gates the `instanceof` check
with `typeof SharedWorker !== "undefined"`, mirroring the existing
`isWorkerLike` pattern for `Worker`. Use it at both `host.ts` call sites.
@baransu baransu force-pushed the tomasz/guard-sharedworker-reference branch from 99236ea to a77a8a3 Compare May 11, 2026 10:53
Copy link
Copy Markdown

@enzomonjardin enzomonjardin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@enzomonjardin enzomonjardin merged commit 18af14c into master May 11, 2026
1 check passed
@baransu baransu mentioned this pull request May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants