lichtblick-suite/lichtblick/web-workers

Claude Code and agent skill by lichtblick-suite/lichtblick

Trust tier 2
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Web Worker patterns used throughout the Lichtblick codebase: Comlink integration, ComlinkWrap lifecycle, transfer handlers, OffscreenCanvas, SharedWorker isolation, and testing utilities.

Install

npx vskill@latest install lichtblick-suite/lichtblick/web-workers

SKILL.md

The same SKILL.md was published earlier as lichtblick-suite/lichtblick/web-workers.

Web Workers Skill

Standard Pattern: ComlinkWrap

All Worker communication in Lichtblick uses Comlink with the ComlinkWrap utility for safe lifecycle management.

Worker Creation (main thread)
typescript
import { ComlinkWrap } from "@lichtblick/den/worker";
const worker = new Worker(
new URL("./MyWorker.worker", import.meta.url), // webpack-compatible URL
);
const { remote, dispose } = ComlinkWrap<MyWorkerAPI>(worker);
// Use the remote API
const result = await remote.process(data);
// Cleanup when done
dispose(); // releases Comlink proxy + terminates worker
Worker Implementation (worker thread)
typescript
import * as Comlink from "@lichtblick/comlink";
class MyWorkerImpl {
async process(data: Uint8Array): Promise<Result> {
// Heavy computation here
return result;
}
}
Comlink.expose(new MyWorkerImpl());
Key file: packages/den/worker/ComlinkWrap.ts

FinalizationRegistry Cleanup

ComlinkWrap returns a dispose function, but the project also uses FinalizationRegistry as a safety net:

typescript
const registry = new FinalizationRegistry<() => void>((dispose) => {
dispose(); // Worker terminated when wrapper is garbage collected
});
// In constructor:
registry.register(this, dispose);

This prevents Worker leaks if the wrapping object is GC'd without explicit disposal.

Transfer Handlers

AbortSignal Transfer
typescript
import { abortSignalTransferHandler } from "@lichtblick/comlink-transfer-handlers";
// Register BEFORE any Comlink communication
Comlink.transferHandlers.set("abortsignal", abortSignalTransferHandler);

Allows passing AbortSignal across Worker boundaries — used by WorkerIterableSource to cancel iteration.

OffscreenCanvas Transfer
typescript
const offscreenCanvas = canvas.transferControlToOffscreen();
const { remote, dispose } = ComlinkWrap<RendererService>(worker);
await remote.init(
Comlink.transfer(
{ canvas: offscreenCanvas, devicePixelRatio: window.devicePixelRatio },
[offscreenCanvas], // Transfer list
),
);

Used by: Plot panel (OffscreenCanvasRenderer), Chart component.

ArrayBuffer Transfer
typescript
// Transfer large binary data to Worker (zero-copy)
await remote.processData(Comlink.transfer(buffer, [buffer.buffer]));
// After transfer: buffer.byteLength === 0 (detached)

Worker URL Pattern (Webpack)

All Worker URLs use the import.meta.url pattern for webpack compatibility:

typescript
new Worker(new URL("./MyWorker.worker", import.meta.url));
  • File must be named *.worker.ts (webpack recognizes this pattern)
  • babel-plugin-transform-import-meta handles the URL resolution
  • Each Worker file is bundled as a separate chunk

SharedWorker Pattern

Used by UserScriptPlayer for script execution:

typescript
new SharedWorker(new URL("./transformerWorker/index", import.meta.url), {
name: uuidv4(), // Unique name prevents sharing between tabs
});
  • SharedWorker chosen for memory efficiency (shared code across script instances)
  • Unique name per instance prevents cross-tab Worker sharing (intentional isolation)

Testing Workers

makeComlinkWorkerMock
typescript
import { makeComlinkWorkerMock } from "@lichtblick/den/testing";
// Replace global Worker constructor with a mock that uses in-process Comlink
Object.defineProperty(global, "Worker", {
writable: true,
value: makeComlinkWorkerMock(() => new ActualImplementation()),
});

Located in packages/den/testing/makeComlinkWorkerMock.ts:

  • Creates an in-process Comlink channel (no actual Worker thread)
  • Allows unit testing Worker-based code without spawning real threads
  • Uses EventEmitter to simulate postMessage / onmessage

Workers in the Codebase

LocationPurposePattern
IterablePlayer/WorkerIterableSource.tsData source parsingComlinkWrap + AbortSignal
Plot/OffscreenCanvasRenderer.tsChart.js renderingComlinkWrap + OffscreenCanvas
Plot/builders/TimestampDatasetsBuilder.tsDataset buildingComlinkWrap + FinalizationRegistry
ThreeDeeRender/renderables/Images/WorkerImageDecoder.tsImage decodingComlinkWrap
UserScriptPlayer/index.tsScript executionSharedWorker + unique name
FoxgloveWebSocketPlayer/WorkerSocketAdapter.tsWebSocket I/ORaw Worker + postMessage
components/Chart/index.tsxLegacy chart renderingWebWorkerManager + Rpc

Performance Considerations

  1. Transfer vs Copy: Always use Comlink.transfer() for large ArrayBuffers
  2. Worker startup: Workers are created lazily — first use incurs startup cost
  3. Proxy cleanup: Always call dispose() or rely on FinalizationRegistry
  4. Message overhead: Small frequent messages have higher overhead than batched large messages
  5. SharedWorker caveats: Debugging is harder (separate DevTools), errors may be silent

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
1,152
Repository forks
750
7-day trend score
35

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/lichtblick-suite/lichtblick/web-workers/badge)](https://verified-skill.com/skills/lichtblick-suite/lichtblick/web-workers)

Something wrong with this skill or its page? Tell us.