feat: add darkMode and hideSelectors screenshot parameters
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 9m31s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 9m31s
- darkMode: emulates prefers-color-scheme: dark before navigation - hideSelectors: injects CSS to hide elements before capture - POST: accepts string or string array - GET: accepts comma-separated string - Validation: max 10 selectors, each max 200 chars - OpenAPI docs updated for both GET and POST endpoints - 13 new tests added (service + route)
This commit is contained in:
parent
9575d312fe
commit
96d21aa63b
5 changed files with 232 additions and 4 deletions
|
|
@ -14,6 +14,8 @@ export interface ScreenshotOptions {
|
|||
deviceScale?: number;
|
||||
delay?: number;
|
||||
waitUntil?: "load" | "domcontentloaded" | "networkidle0" | "networkidle2";
|
||||
darkMode?: boolean;
|
||||
hideSelectors?: string[];
|
||||
}
|
||||
|
||||
export interface ScreenshotResult {
|
||||
|
|
@ -42,6 +44,10 @@ export async function takeScreenshot(opts: ScreenshotOptions): Promise<Screensho
|
|||
try {
|
||||
await page.setViewport({ width, height, deviceScaleFactor: deviceScale });
|
||||
|
||||
if (opts.darkMode) {
|
||||
await page.emulateMediaFeatures([{ name: 'prefers-color-scheme', value: 'dark' }]);
|
||||
}
|
||||
|
||||
await Promise.race([
|
||||
(async () => {
|
||||
await page.goto(opts.url, { waitUntil, timeout: 20_000 });
|
||||
|
|
@ -53,6 +59,12 @@ export async function takeScreenshot(opts: ScreenshotOptions): Promise<Screensho
|
|||
if (opts.delay && opts.delay > 0) {
|
||||
await new Promise(r => setTimeout(r, Math.min(opts.delay!, 5000)));
|
||||
}
|
||||
|
||||
if (opts.hideSelectors && opts.hideSelectors.length > 0) {
|
||||
await page.addStyleTag({
|
||||
content: opts.hideSelectors.map(s => s + ' { display: none !important }').join('\n')
|
||||
});
|
||||
}
|
||||
})(),
|
||||
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("SCREENSHOT_TIMEOUT")), TIMEOUT_MS)),
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue