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

canvas-screenshot

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas-screenshot - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

40

index.js

@@ -18,3 +18,5 @@ const fileExtension = require("file-extension");

.replace(/:/g, ".")}.png`,
quality = 1
quality = 1,
useBlob,
download = true
} = {

@@ -24,10 +26,36 @@ ...options

link = link || document.createElement("a");
link.download = filename;
link.href = canvas.toDataURL(`${getType(filename)};base64`, quality);
if (download) {
link = link || document.createElement("a");
link.download = filename;
}
const event = new MouseEvent("click");
link.dispatchEvent(event);
if (useBlob) {
return new Promise(resolve => {
canvas.toBlob(
blob => {
if (download) {
link.href = URL.createObjectURL(blob);
const event = new MouseEvent("click");
link.dispatchEvent(event);
}
resolve(blob);
},
getType(filename),
quality
);
});
}
const dataURL = canvas.toDataURL(`${getType(filename)};base64`, quality);
if (download) {
link.href = dataURL;
const event = new MouseEvent("click");
link.dispatchEvent(event);
}
return dataURL;
}
module.exports = takeCanvasScreenshot;

6

package.json
{
"name": "canvas-screenshot",
"version": "1.1.1",
"version": "2.0.0",
"description": "A one trick pony package to download an image from a canvas.",

@@ -12,4 +12,4 @@ "main": "index.js",

"devDependencies": {
"budo": "^11.6.1",
"canvas-context": "^1.0.1"
"budo": "^11.6.2",
"canvas-context": "^1.0.3"
},

@@ -16,0 +16,0 @@ "dependencies": {

@@ -37,10 +37,15 @@ # canvas-screenshot [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

### `canvasScreenshot(canvas, options)`
### `canvasScreenshot(canvas, options): DOMString | Promise<Blob>`
| Option | Type | Default | Description |
| -------------------- | ----------------- | ---------------------------------------- | ----------------------- |
| **canvas** | HTMLCanvasElement | | The canvas element |
| **options.filename** | string? | `Screen Shot YYYY-MM-DD at HH.MM.SS.png` | File name |
| **options.quality** | number? | 1 | Quality between 0 and 1 |
Returns a `Data URI` or a Promise resolving with a Blob.
Setting `useBlob` to `true` will consequently make the module async and return the latter.
| Option | Type | Default | Description |
| -------------------- | ----------------- | ---------------------------------------- | ------------------------------------- |
| **canvas** | HTMLCanvasElement | | The canvas element |
| **options.filename** | string? | `Screen Shot YYYY-MM-DD at HH.MM.SS.png` | File name |
| **options.quality** | number? | 1 | Quality between 0 and 1 |
| **options.useBlob** | boolean? | undefined | Use `canvas.toBlob` |
| **options.download** | boolean? | true | Automatically download the screenshot |
Type is inferred from the filename extension (jpg/jpeg) for `"image/jpeg"` and default to `"image/png"`.

@@ -47,0 +52,0 @@

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