New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

browser-capture-screenshot

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-capture-screenshot

[![Github Repository](https://img.shields.io/badge/amoshydra-browser--capture--screenshot-black?style=flat&logo=github)](https://github.com/amoshydra/browser-capture-screenshot) [![NPM Version](https://img.shields.io/npm/v/browser-capture-screenshot)](htt

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Browser Capture Screenshot

Github Repository NPM Version npm bundle size GitHub 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-screenshot

Demo

See demo at https://amoshydra.github.io/browser-capture-screenshot

preview

Usage

import { capture } from "browser-capture-screenshot";

const screenshot = await capture(demoElement);
previewElement.src = screenshot;

ScreenshotSession provides more granular controls:

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);

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.

  • { api: "element" } - uses Element Capture API
  • { api: "region" } - uses Region Capture API

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:

  • When using Element Capture API:
    • requires >= Chrome 132
    • the target element need to be eligible for restriction
    • the target element by default has a black background. If your element is tranparent, it will blend with a black background.
    • The following style can be used with Element Capture API:
      .target {
        background-color: white; /* provide a background */
        isolation: isolate; /* make target eligible for restriction */
      }
      
  • The capture region need to be visible in the viewport
  • System UI (such as context menu) or User Agent widget (i.e. Date Picker, Select option list) will not be captured

References

References

Similar projects

Keywords

FAQs

Package last updated on 03 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc