Files
stack/packages/mosaic/framework/skills/vueuse-functions/references/useWebWorker.md
T
fargo 1a822493ba format: apply repo prettier (3.8.1) to the folded skills tree
963 markdown files reformatted with the repository's pinned prettier so
pnpm format:check covers the folded tree like every other repo file.

The formatter's embedded-language pass also normalized code fences
(TS semicolons, closed HTML tags in examples, lowercased CSS hex colors,
one renumbered list that skipped an index). Alphanumeric token deltas vs
the fold commit were audited file-by-file; all are formatter-equivalent
markup normalizations plus the four sanitized skills.
2026-08-19 14:37:17 -05:00

2.4 KiB

category, related
category related
Browser useWebWorkerFn

useWebWorker

Simple Web Workers registration and communication.

Usage

import { useWebWorker } from '@vueuse/core';

const { data, post, terminate, worker } = useWebWorker('/path/to/worker.js');
State Type Description
data Ref<any> Reference to the latest data received via the worker, can be watched to respond to incoming messages
worker ShallowRef<Worker | undefined> Reference to the instance of the WebWorker
Method Signature Description
post (message: any, transfer: Transferable[]): void
(message: any, options?: StructuredSerializeOptions | undefined): void
Sends data to the worker thread.
terminate () => void Stops and terminates the worker.

Type Declarations

type PostMessage = (typeof Worker.prototype)['postMessage'];
export interface UseWebWorkerReturn<Data = any> {
  data: Ref<Data>;
  post: PostMessage;
  terminate: () => void;
  worker: ShallowRef<Worker | undefined>;
}
type WorkerFn = (...args: unknown[]) => Worker;
/**
 * Simple Web Workers registration and communication.
 *
 * @see https://vueuse.org/useWebWorker
 * @param url
 * @param workerOptions
 * @param options
 */
export declare function useWebWorker<T = any>(
  url: string,
  workerOptions?: WorkerOptions,
  options?: ConfigurableWindow,
): UseWebWorkerReturn<T>;
/**
 * Simple Web Workers registration and communication.
 *
 * @see https://vueuse.org/useWebWorker
 */
export declare function useWebWorker<T = any>(worker: Worker | WorkerFn): UseWebWorkerReturn<T>;