Browser Capture Screen

Github RepositoryNPM Versionnpm bundle sizeGitHub License

Browser Capture Screenshot utilises Element Capture API or Region Capture API to capture screenshot of a given Element from the page.

npm install browser-capture-screen
Demo
πŸ“ΈπŸ‘½πŸ›πŸͺ‘πŸ¦Έβ€β™€οΈπŸ€πŸ’Ύ
 
import { capture } from "browser-capture-screenshot"; const screenshot = await capture(demoElement); previewElement.src = screenshot;
Your browser is not compatible


Granular controls

ScreenshotSession provides more granular controls:

Demo
πŸ“ΈπŸ‘½πŸ›πŸͺ‘πŸ¦Έβ€β™€οΈπŸ€πŸ’Ύ
 
import { ScreenshotSession } from "browser-capture-screenshot"; const session = new ScreenshotSession(); await session.start(); // capture screenshot 1 second later setTimeout(async () => { const screenshot = await session.capture(demoElement); previewElement.src = screenshot; await session.stop(); }, 1000);
Your browser is not compatible

API

capture

A simplified API for capturing screenshot. This method uses ScreenshotSession internally.

export function capture(element: HTMLElement, options?: CaptureOptions): Promise<string>

return

A base64 encoded string representing the captured image wrapped in a Promise. e.g.: data:image/png;base64,iVBORw0K....

param element

The element HTMLElement to take screenshot of.

param options

optional.

param options.api

optional. Specify how the screenshot should be captured.

Default to using Element Capture API when not specified.

ScreenshotSession

export class ScreenshotSession {
  static isSupported(): boolean;
  start(): Promise<void>
  stop()
  capture(element: HTMLElement, options?: CaptureOptions): Promise<string>
}

Compatibility

This implementation requires the browser to support the following experimental API:

Notes:

References

References

Similar projects