Skip to content

Commit 5a6b457

Browse files
committed
Meta tweaks
1 parent ef50619 commit 5a6b457

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

index.js

+35-19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import process from 'node:process';
33
import fs from 'node:fs/promises';
44
import path from 'node:path';
5+
import {setTimeout} from 'node:timers/promises';
56
import fileUrl from 'file-url';
67
import puppeteer, {KnownDevices} from 'puppeteer';
78
import toughCookie from 'tough-cookie';
@@ -111,7 +112,15 @@ const disableAnimations = () => {
111112

112113
const getBoundingClientRect = element => {
113114
const {top, left, height, width, x, y} = element.getBoundingClientRect();
114-
return {top, left, height, width, x, y};
115+
116+
return {
117+
top,
118+
left,
119+
height,
120+
width,
121+
x,
122+
y,
123+
};
115124
};
116125

117126
const parseCookie = (url, cookie) => {
@@ -130,9 +139,7 @@ const parseCookie = (url, cookie) => {
130139
returnValue.name = returnValue.key;
131140
delete returnValue.key;
132141

133-
if (returnValue.expires) {
134-
returnValue.expires = Math.floor(new Date(returnValue.expires) / 1000);
135-
}
142+
returnValue.expires &&= Math.floor(new Date(returnValue.expires) / 1000);
136143

137144
return returnValue;
138145
};
@@ -312,7 +319,7 @@ const internalCaptureWebsiteCore = async (input, options, page, browser) => {
312319
await page.click(options.clickElement);
313320
}
314321

315-
const getInjectKey = (ext, value) => isUrl(value) ? 'url' : (value.endsWith(`.${ext}`) ? 'path' : 'content');
322+
const getInjectKey = (extension, value) => isUrl(value) ? 'url' : (value.endsWith(`.${extension}`) ? 'path' : 'content');
316323

317324
if (!options.isJavaScriptEnabled) {
318325
// Enable JavaScript again for `modules` and `scripts`.
@@ -357,7 +364,7 @@ const internalCaptureWebsiteCore = async (input, options, page, browser) => {
357364
}
358365

359366
if (options.delay) {
360-
await page.waitForTimeout(options.delay * 1000);
367+
await setTimeout(options.delay * 1000);
361368
}
362369

363370
if (options.element) {
@@ -405,23 +412,27 @@ const internalCaptureWebsiteCore = async (input, options, page, browser) => {
405412
}
406413

407414
if (options.inset && !screenshotOptions.fullPage) {
408-
const inset = {top: 0, right: 0, bottom: 0, left: 0};
415+
const inset = {
416+
top: 0,
417+
right: 0,
418+
bottom: 0,
419+
left: 0,
420+
};
421+
409422
for (const key of Object.keys(inset)) {
410-
inset[key] = typeof options.inset === 'number' ? options.inset : options.inset[key] || 0;
423+
inset[key] = typeof options.inset === 'number' ? options.inset : (options.inset[key] ?? 0);
411424
}
412425

413426
let clipOptions = screenshotOptions.clip;
414427

415-
if (!clipOptions) {
416-
clipOptions = await page.evaluate(() => ({
417-
x: 0,
418-
y: 0,
419-
/* eslint-disable no-undef */
420-
height: window.innerHeight,
421-
width: window.innerWidth,
422-
/* eslint-enable no-undef */
423-
}));
424-
}
428+
clipOptions ||= await page.evaluate(() => ({
429+
x: 0,
430+
y: 0,
431+
/* eslint-disable no-undef */
432+
height: window.innerHeight,
433+
width: window.innerWidth,
434+
/* eslint-enable no-undef */
435+
}));
425436

426437
const x = clipOptions.x + inset.left;
427438
const y = clipOptions.y + inset.top;
@@ -432,7 +443,12 @@ const internalCaptureWebsiteCore = async (input, options, page, browser) => {
432443
throw new Error('When using the `clip` option, the width or height of the screenshot cannot be equal to 0.');
433444
}
434445

435-
screenshotOptions.clip = {x, y, width, height};
446+
screenshotOptions.clip = {
447+
x,
448+
y,
449+
width,
450+
height,
451+
};
436452
}
437453

438454
const buffer = await page.screenshot(screenshotOptions);

package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"jpeg"
4444
],
4545
"dependencies": {
46-
"@cliqz/adblocker-puppeteer": "^1.26.11",
46+
"@cliqz/adblocker-puppeteer": "^1.27.2",
4747
"file-url": "^4.0.0",
4848
"puppeteer": "^21.9.0",
4949
"tough-cookie": "^4.1.3"
@@ -52,14 +52,17 @@
5252
"ava": "^5.3.1",
5353
"create-test-server": "^3.0.1",
5454
"delay": "^6.0.0",
55-
"image-dimensions": "^2.0.0",
55+
"image-dimensions": "^2.3.0",
5656
"is-jpg": "^3.0.0",
5757
"is-png": "^3.0.1",
5858
"pify": "^6.1.0",
5959
"png-js": "^1.0.0",
6060
"tempy": "^3.1.0",
61-
"tsd": "^0.29.0",
62-
"uint8array-extras": "^0.5.0",
63-
"xo": "^0.56.0"
61+
"tsd": "^0.31.0",
62+
"uint8array-extras": "^1.1.0",
63+
"xo": "^0.58.0"
64+
},
65+
"ava": {
66+
"serial": true
6467
}
6568
}

0 commit comments

Comments
 (0)