LearnNewsExamplesServices
Frontmatter
id8496
titleServiceWorker missing hasWorker() method causes initRemote failure
stateClosed
labels
bugaicore
assigneestobiu
createdAtJan 10, 2026, 12:17 PM
updatedAtJan 10, 2026, 12:19 PM
githubUrlhttps://github.com/neomjs/neo/issues/8496
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 10, 2026, 12:19 PM

ServiceWorker missing hasWorker() method causes initRemote failure

Closed v11.20.0 bugaicore
tobiu
tobiu commented on Jan 10, 2026, 12:17 PM

The Service Worker fails to initialize remote methods because it lacks the hasWorker() method, which is required by Neo.core.Base.promiseRemotes().

The Error:

Base.mjs:892 Uncaught (in promise) TypeError: origin.hasWorker is not a function
    at Base.mjs:892:28
    at Array.forEach (<anonymous>)
    at Base.promiseRemotes (Base.mjs:888:32)
    at ServiceWorker.initRemote (Base.mjs:648:24)
    at ServiceWorker.initRemote (ServiceBase.mjs:172:19)
    at ServiceWorker.onConnect (ServiceBase.mjs:203:14)
    at ServiceWorker.onRegisterNeoConfig (ServiceBase.mjs:297:14)
    at ServiceWorker.onMessage (ServiceBase.mjs:272:39)

Root Cause: Neo.core.Base.promiseRemotes() checks origin.hasWorker(worker) before sending a message. In the context of a Service Worker, origin is the ServiceWorker instance itself (which extends ServiceBase). However, ServiceBase does not implement hasWorker(), unlike Neo.worker.Base and Neo.worker.Manager.

Fix: Implement hasWorker(name) in src/worker/ServiceBase.mjs. Since the Service Worker communicates via this.sendMessage, which checks channelPorts or lastClient, the implementation should check if a valid destination exists.

For the Service Worker, a "worker" (destination) is available if:

  1. It is 'app' (main communication channel).
  2. We have a connected client or port for it.
tobiu added the bug label on Jan 10, 2026, 12:17 PM
tobiu added the ai label on Jan 10, 2026, 12:17 PM
tobiu added the core label on Jan 10, 2026, 12:17 PM
tobiu assigned to @tobiu on Jan 10, 2026, 12:17 PM
tobiu referenced in commit 3e6aece - "fix: Implement hasWorker() in ServiceBase to allow initRemote calls (#8496)" on Jan 10, 2026, 12:18 PM
tobiu
tobiu Jan 10, 2026, 12:19 PM

Input from tobiu:

◆ Implemented hasWorker(name) in src/worker/ServiceBase.mjs.

This method is required by Neo.core.Base.promiseRemotes() to check if a target worker (destination) is available before sending a message.

Implementation Details:

  • hasWorker(name) returns true if:
    • The destination is 'app' (the main channel).
    • A specific message port exists for the destination.
    • A fallback client (lastClient) is available.

This fix ensures that initRemote() calls within the Service Worker context no longer throw TypeError: origin.hasWorker is not a function.

tobiu closed this issue on Jan 10, 2026, 12:19 PM