happy-opfs
    Preparing search index...

    Function connect

    • Connects to a worker and establishes a sync channel for synchronous file system operations. Must be called before using any sync API functions.

      Parameters

      • worker: string | URL | Worker

        The worker to communicate with. Can be a Worker instance, a URL, or a URL string.

      • Optionaloptions: ConnectSyncChannelOptions

        Optional configuration options for the sync channel.

      Returns AsyncIOResult<SharedArrayBuffer>

      A promise that resolves with an AsyncIOResult containing the SharedArrayBuffer when the worker is ready. The returned buffer can be shared with other contexts (e.g., iframes) via postMessage.

      1.1.0

      // Connect to worker and get SharedArrayBuffer
      const result = await SyncChannel.connect(
      new URL('./worker.js', import.meta.url),
      { sharedBufferLength: 1024 * 1024, opTimeout: 5000 }
      );
      result.inspect(sharedBuffer => {
      // Share with iframe
      iframe.contentWindow.postMessage({ sharedBuffer }, '*');
      });