Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pixeleye/cli-capture

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixeleye/cli-capture - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

86

dist/index.js

@@ -1,1 +0,85 @@

import{createCache as h,createMirror as p,rebuild as C}from"rrweb-snapshot";import{chromium as w,firefox as f,webkit as u}from"playwright-core";import d from"object-hash";var i={},g={chromium:w,firefox:f,webkit:u};async function s(e){let t=d(e);if(i[t])return i[t];let r=g[e.defaultBrowserType];if(!r)throw new Error(`Unknown renderer ${e.defaultBrowserType}`);let n=await(await r.launch()).newContext(e);return i[t]=n,n}import{defaultConfig as x}from"@pixeleye/cli-config";import{JSDOM as k}from"jsdom";function z(e){let t=new k().window.document,r=h(),o=p();return C(e,{doc:t,cache:r,mirror:o}),t.documentElement.outerHTML}async function L(e){let r=await(await s(e.device)).newPage();if(e.url)await r.goto(e.url);else if(e.content)await r.setContent(e.content,{timeout:6e4});else throw await r.close(),new Error("No url or serializedDom provided");e.css&&await r.locator("body").first().evaluate((a,m)=>{let c=document.createElement("style");return c.innerHTML=m,a.appendChild(c),!0},e.css),await r.waitForLoadState(),e.selector&&await r.waitForSelector(e.selector,{timeout:6e4});let o=e.selector?r.locator(e.selector):r,n=[...e?.maskSelectors||[],"[data-pixeleye-mask]"].map(a=>o.locator(a)),l=await o.screenshot({fullPage:e.fullPage,type:"png",mask:n,maskColor:e?.maskColor||x.maskColor});return await r.close(),l}export{L as captureScreenshot,s as getBrowser,z as getBuildContent};
// src/capture.ts
import {
createCache,
createMirror,
rebuild
} from "rrweb-snapshot";
// src/browsers.ts
import { chromium, firefox, webkit } from "playwright-core";
import hash from "object-hash";
var deviceCache = {};
var renderEngines = {
chromium,
firefox,
webkit
};
async function getBrowser(deviceDescriptor) {
const key = hash(deviceDescriptor);
if (deviceCache[key]) {
return deviceCache[key];
}
const renderer = renderEngines[deviceDescriptor.defaultBrowserType];
if (!renderer) {
throw new Error(`Unknown renderer ${deviceDescriptor.defaultBrowserType}`);
}
const browser = await renderer.launch();
const context = await browser.newContext(deviceDescriptor);
deviceCache[key] = context;
return context;
}
// src/capture.ts
import { defaultConfig } from "@pixeleye/cli-config";
import { JSDOM } from "jsdom";
function getBuildContent(serializedDom) {
const doc = new JSDOM().window.document;
const cache = createCache();
const mirror = createMirror();
rebuild(serializedDom, { doc, cache, mirror });
return doc.documentElement.outerHTML;
}
async function captureScreenshot(options) {
const browser = await getBrowser(options.device);
const page = await browser.newPage();
if (options.url) {
await page.goto(options.url);
} else if (options.content) {
await page.setContent(options.content, {
timeout: 6e4
});
} else {
await page.close();
throw new Error("No url or serializedDom provided");
}
if (options.css) {
await page.locator("body").first().evaluate((body, css) => {
const style = document.createElement("style");
style.innerHTML = css;
body.appendChild(style);
return true;
}, options.css);
}
await page.waitForLoadState();
if (options.selector)
await page.waitForSelector(options.selector, {
timeout: 6e4
});
const locatedPage = options.selector ? page.locator(options.selector) : page;
const mask = [...options?.maskSelectors || [], "[data-pixeleye-mask]"].map(
(selector) => locatedPage.locator(selector)
);
const file = await locatedPage.screenshot({
fullPage: options.fullPage,
type: "png",
mask,
maskColor: options?.maskColor || defaultConfig.maskColor
});
await page.close();
return file;
}
export {
captureScreenshot,
getBrowser,
getBuildContent
};

6

package.json
{
"name": "@pixeleye/cli-capture",
"version": "0.4.0",
"version": "0.4.1",
"private": false,

@@ -21,3 +21,3 @@ "license": "AGPL-3.0",

"rimraf": "^5.0.5",
"@pixeleye/cli-config": "0.4.0",
"@pixeleye/cli-config": "0.4.1",
"@pixeleye/esbuild": "0.0.0",

@@ -34,3 +34,3 @@ "@pixeleye/eslint-config": "0.0.0",

"rrweb-snapshot": "2.0.0-alpha.11",
"@pixeleye/cli-devices": "0.4.0"
"@pixeleye/cli-devices": "0.4.1"
},

@@ -37,0 +37,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

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