@pixeleye/cli-capture
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -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 | ||
}; |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
44397
221
2
1
+ Added@pixeleye/cli-devices@0.4.1(transitive)
- Removed@pixeleye/cli-devices@0.4.0(transitive)
Updated@pixeleye/cli-devices@0.4.1