Skip to content

Worker extension host: 'self.addEventListener' is blocked #28

@char0n

Description

@char0n

Where it shows up

When the extension activates inside the monaco-vscode-api web worker extension host, the browser console logs (3+ times per activation):

extensionHost.worker-<hash>.js:45 'addEventListener' has been blocked
  self.addEventListener @ extensionHost.worker-<hash>.js:45
  eval @ speclynxClientMain.js:9
  eval @ speclynxClientMain.js:9
  eval @ speclynxClientMain.js:9
  _loadCommonJSModule @ extensionHost.worker-<hash>.js:45

What's happening

speclynxClientMain.js (the bundled extension entry, loaded as a CommonJS module by the worker extension host) calls self.addEventListener(...) at module scope. The host froze self before evaluating the extension module, so the call is silently rejected. The toolkit continues to work — Scalar preview renders, language features activate — but the warning fires every activation.

Repro

Observed in https://github.com/speclynx/speclynx-editor running monaco-vscode-api 32.x with the bundled VSIX. Should also reproduce in vscode.dev / github.dev or any other web host that loads the toolkit through the web worker extension host.

Suggested fix

Drop the top-level self.addEventListener(...) call (or guard it) and use the corresponding VSCode API. If the listener is required for a specific feature, please document which so it can be ported to a worker-safe equivalent.

if (typeof self !== 'undefined' && typeof self.addEventListener === 'function') {
  try { self.addEventListener(eventName, handler) } catch { /* sandboxed host */ }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions