Documentation / /
Web APIs

capturePage API

experimental.capturePage is an experimental API for capturing a screenshot of a page.

To use this API, include the following in your dat.json manifest file:

{
  "experimental": {
    "apis": ["capturePage"]
  }
}

Permissions

The user must grant permission for your app to use this API.

Privacy

To avoid leaking sensitive user data in the screenshot, Beaker loads the page in a temporary private session. The screenshot will show no login state, visited links, or any other indicator of the user’s past behaviors.

Methods

experimental.capturePage(url, opts?)

Loads the given URL in a hidden webview and takes a screenshot of the content.

The user will be prompted to give permission before taking the screenshot.

  • url String. The URL of the resource to be captured.
  • opts.width Number. The width of the page to capture. Cannot be greater than 1600. Defaults to 1024.
  • opts.height Number. The height of the page to capture. Cannot be greater than 1200. Defaults to 768.
  • opts.resizeTo.width Number. Resizes the captured image to the given width. Cannot be greater than 1600.
  • opts.resizeTo.height Number. Resizes the captured image to the given height. Cannot be greater than 1200.
  • returns Promise<ArrayBuffer>. A PNG-format image.

Examples:

var png = await experimental.capturePage('dat://beakerbrowser.com', {
  width: 640,
  height: 480
})
await myArchive.writeFile('/screenshot.png', png)
var png = await experimental.capturePage('dat://beakerbrowser.com', {
  width: 640,
  height: 480,
  resizeTo: {width: 80, height: 60}
})
await myArchive.writeFile('/thumbnail.png', png)