method
WebView.screenshot
Capture a screenshot of the current viewport.
encoding controls the return type:
"blob"(default) —Blobwith the right MIME type. WebKit: zero-copy mmap-backed store. Composes withBun.write(),new Response(),blob.bytes()."buffer"— NodeBuffer. WebKit: zero-copy (the same mmap'd pages wrapped as anArrayBufferthat munmap's on GC)."base64"— base64-encodedstring. Chrome: zero decode (CDP returns base64 natively). Direct Kittyt=dtransmission."shmem"—{ name, size }. The POSIX shm name is left linked; caller ownsshm_unlink. Kittyt=stransmission: passnameas 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.Capture a screenshot of the current viewport.
encoding controls the return type:
"blob"(default) —Blobwith the right MIME type. WebKit: zero-copy mmap-backed store. Composes withBun.write(),new Response(),blob.bytes()."buffer"— NodeBuffer. WebKit: zero-copy (the same mmap'd pages wrapped as anArrayBufferthat munmap's on GC)."base64"— base64-encodedstring. Chrome: zero decode (CDP returns base64 natively). Direct Kittyt=dtransmission."shmem"—{ name, size }. The POSIX shm name is left linked; caller ownsshm_unlink. Kittyt=stransmission: passnameas 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.Capture a screenshot of the current viewport.
encoding controls the return type:
"blob"(default) —Blobwith the right MIME type. WebKit: zero-copy mmap-backed store. Composes withBun.write(),new Response(),blob.bytes()."buffer"— NodeBuffer. WebKit: zero-copy (the same mmap'd pages wrapped as anArrayBufferthat munmap's on GC)."base64"— base64-encodedstring. Chrome: zero decode (CDP returns base64 natively). Direct Kittyt=dtransmission."shmem"—{ name, size }. The POSIX shm name is left linked; caller ownsshm_unlink. Kittyt=stransmission: passnameas 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.Capture a screenshot of the current viewport.
encoding controls the return type:
"blob"(default) —Blobwith the right MIME type. WebKit: zero-copy mmap-backed store. Composes withBun.write(),new Response(),blob.bytes()."buffer"— NodeBuffer. WebKit: zero-copy (the same mmap'd pages wrapped as anArrayBufferthat munmap's on GC)."base64"— base64-encodedstring. Chrome: zero decode (CDP returns base64 natively). Direct Kittyt=dtransmission."shmem"—{ name, size }. The POSIX shm name is left linked; caller ownsshm_unlink. Kittyt=stransmission: passnameas 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.
Returns a promise that resolves to the contents of the blob as an ArrayBuffer
Returns a promise that resolves to the contents of the blob as a Uint8Array (array of bytes). Equivalent to
new Uint8Array(await blob.arrayBuffer())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-databody or anapplication/x-www-form-urlencodedbody.The blob's
typeproperty determines the format of the body.This is a non-standard addition to the
BlobAPI, to make it conform more closely to theBodyMixinAPI.Wrap this blob in a Bun.Image pipeline. Equivalent to
new Bun.Image(this, options)— the constructor is synchronous (the underlying read happens lazily when an Image terminal is awaited), so this works onBun.file(),Bun.s3(), fd-backed and in-memory blobs alike:await Bun.file("photo.jpg").image().resize(400).webp().write("thumb.webp");Read the data from the blob as a JSON object.
This first decodes the data from UTF-8, then parses it as JSON.
Returns a readable stream of the blob's contents
Returns a promise that resolves to the contents of the blob as a string