-
-
Notifications
You must be signed in to change notification settings - Fork 742
/
index.js
44 lines (38 loc) · 1.17 KB
/
index.js
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
'use strict'
const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
/**
* Fix missing window.outerWidth/window.outerHeight in headless mode
* Will also set the viewport to match window size, unless specified by user
*/
class Plugin extends PuppeteerExtraPlugin {
constructor(opts = {}) {
super(opts)
}
get name() {
return 'stealth/evasions/window.outerdimensions'
}
async onPageCreated(page) {
// Chrome returns undefined, Firefox false
await page.evaluateOnNewDocument(() => {
try {
if (window.outerWidth && window.outerHeight) {
return // nothing to do here
}
const windowFrame = 85 // probably OS and WM dependent
window.outerWidth = window.innerWidth
window.outerHeight = window.innerHeight + windowFrame
} catch (err) {}
})
}
async beforeLaunch(options) {
// Have viewport match window size, unless specified by user
// https://github.com/GoogleChrome/puppeteer/issues/3688
if (!('defaultViewport' in options)) {
options.defaultViewport = null
}
return options
}
}
module.exports = function(pluginConfig) {
return new Plugin(pluginConfig)
}