forked from Sparticuz/chrome-aws-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.ts
47 lines (39 loc) · 1.07 KB
/
window.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Page } from 'puppeteer-core';
/**
* Patches window outer dimentions to mimic headful Chrome.
*
* @param page - Page to hook to.
*/
export = async function (page: Page): Promise<Page> {
const handler = () => {
if (window.outerWidth === 0) {
Object.defineProperty(window, 'outerWidth', {
get: () => screen.availWidth,
});
}
if (window.outerHeight === 0) {
Object.defineProperty(window, 'outerHeight', {
get: () => screen.availHeight,
});
}
if (window.screenX === 0) {
Object.defineProperty(window, 'screenX', {
get: () => screen.width - screen.availWidth,
});
Object.defineProperty(window, 'screenLeft', {
get: () => screenX,
});
}
if (window.screenY === 0) {
Object.defineProperty(window, 'screenY', {
get: () => screen.height - screen.availHeight,
});
Object.defineProperty(window, 'screenTop', {
get: () => screenY,
});
}
};
await page.evaluate(handler);
await page.evaluateOnNewDocument(handler);
return page;
}