Mscreenshot
Bun

method

WebView.screenshot

options?: { encoding: 'blob'; format: 'png' | 'jpeg' | 'webp'; quality: number }
): Promise<Blob>;

Capture a screenshot of the current viewport.

encoding controls the return type:

  • "blob" (default) — Blob with the right MIME type. WebKit: zero-copy mmap-backed store. Composes with Bun.write(), new Response(), blob.bytes().
  • "buffer" — Node Buffer. WebKit: zero-copy (the same mmap'd pages wrapped as an ArrayBuffer that munmap's on GC).
  • "base64" — base64-encoded string. Chrome: zero decode (CDP returns base64 natively). Direct Kitty t=d transmission.
  • "shmem"{ name, size }. The POSIX shm name is left linked; caller owns shm_unlink. Kitty t=s transmission: pass name as the payload, Kitty unlinks after reading. Not on Windows.
const { name, size } = await view.screenshot({ encoding: "shmem" });
process.stdout.write(
  `\x1b_Gf=100,t=s,a=T,S=${size};${btoa(name)}\x1b\\`
);
// Kitty shm_open's the name, reads ${size} PNG bytes, unlinks.
options: { encoding: 'buffer'; format: 'png' | 'jpeg' | 'webp'; quality: number }
): Promise<Buffer<ArrayBufferLike>>;

Capture a screenshot of the current viewport.

encoding controls the return type:

  • "blob" (default) — Blob with the right MIME type. WebKit: zero-copy mmap-backed store. Composes with Bun.write(), new Response(), blob.bytes().
  • "buffer" — Node Buffer. WebKit: zero-copy (the same mmap'd pages wrapped as an ArrayBuffer that munmap's on GC).
  • "base64" — base64-encoded string. Chrome: zero decode (CDP returns base64 natively). Direct Kitty t=d transmission.
  • "shmem"{ name, size }. The POSIX shm name is left linked; caller owns shm_unlink. Kitty t=s transmission: pass name as the payload, Kitty unlinks after reading. Not on Windows.
const { name, size } = await view.screenshot({ encoding: "shmem" });
process.stdout.write(
  `\x1b_Gf=100,t=s,a=T,S=${size};${btoa(name)}\x1b\\`
);
// Kitty shm_open's the name, reads ${size} PNG bytes, unlinks.
options: { encoding: 'base64'; format: 'png' | 'jpeg' | 'webp'; quality: number }
): Promise<string>;

Capture a screenshot of the current viewport.

encoding controls the return type:

  • "blob" (default) — Blob with the right MIME type. WebKit: zero-copy mmap-backed store. Composes with Bun.write(), new Response(), blob.bytes().
  • "buffer" — Node Buffer. WebKit: zero-copy (the same mmap'd pages wrapped as an ArrayBuffer that munmap's on GC).
  • "base64" — base64-encoded string. Chrome: zero decode (CDP returns base64 natively). Direct Kitty t=d transmission.
  • "shmem"{ name, size }. The POSIX shm name is left linked; caller owns shm_unlink. Kitty t=s transmission: pass name as the payload, Kitty unlinks after reading. Not on Windows.
const { name, size } = await view.screenshot({ encoding: "shmem" });
process.stdout.write(
  `\x1b_Gf=100,t=s,a=T,S=${size};${btoa(name)}\x1b\\`
);
// Kitty shm_open's the name, reads ${size} PNG bytes, unlinks.
options: { encoding: 'shmem'; format: 'png' | 'jpeg' | 'webp'; quality: number }
): Promise<{ name: string; size: number }>;

Capture a screenshot of the current viewport.

encoding controls the return type:

  • "blob" (default) — Blob with the right MIME type. WebKit: zero-copy mmap-backed store. Composes with Bun.write(), new Response(), blob.bytes().
  • "buffer" — Node Buffer. WebKit: zero-copy (the same mmap'd pages wrapped as an ArrayBuffer that munmap's on GC).
  • "base64" — base64-encoded string. Chrome: zero decode (CDP returns base64 natively). Direct Kitty t=d transmission.
  • "shmem"{ name, size }. The POSIX shm name is left linked; caller owns shm_unlink. Kitty t=s transmission: pass name as the payload, Kitty unlinks after reading. Not on Windows.
const { name, size } = await view.screenshot({ encoding: "shmem" });
process.stdout.write(
  `\x1b_Gf=100,t=s,a=T,S=${size};${btoa(name)}\x1b\\`
);
// Kitty shm_open's the name, reads ${size} PNG bytes, unlinks.

Referenced types

class Blob

A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system.

MDN Reference

  • readonly size: number
  • readonly type: string
  • Returns a promise that resolves to the contents of the blob as an ArrayBuffer

  • bytes(): Promise<Uint8Array<ArrayBufferLike>>;

    Returns a promise that resolves to the contents of the blob as a Uint8Array (array of bytes) its the same as new Uint8Array(await blob.arrayBuffer())

  • formData(): Promise<FormData>;

    Read the data from the blob as a FormData object.

    This first decodes the data from UTF-8, then parses it as a multipart/form-data body or a application/x-www-form-urlencoded body.

    The type property of the blob is used to determine the format of the body.

    This is a non-standard addition to the Blob API, to make it conform more closely to the BodyMixin API.

  • json(): Promise<any>;

    Read the data from the blob as a JSON object.

    This first decodes the data from UTF-8, then parses it as JSON.

  • start?: number,
    end?: number,
    contentType?: string
    ): Blob;
  • Returns a readable stream of the blob's contents

  • text(): Promise<string>;

    Returns a promise that resolves to the contents of the blob as a string