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

@baransubaransu commented May 11, 2026

Copy link
Copy Markdown

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

@devin-ai-integrationdevin-ai-integrationBot left a comment

Copy link
Copy Markdown

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

@baransubaransu self-assigned this May 11, 2026
`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
baransuforce-pushed the tomasz/guard-sharedworker-reference branch from 99236ea to a77a8a3CompareMay 11, 2026 10:53

@enzomonjardinenzomonjardin left a comment

Copy link
Copy Markdown

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 masterMay 11, 2026
1 check passed
@baransubaransu mentioned this pull request May 11, 2026
Sign up for freeto 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

@baransu@enzomonjardin