@browserless/goto 9.3.0-beta.9 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/engine.bin +0 -0
- package/src/index.js +37 -29
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@browserless/goto",
|
|
3
3
|
"description": "Go to a page aborting unnecessary requests",
|
|
4
4
|
"homepage": "https://browserless.js.org/#/?id=gotopage-options",
|
|
5
|
-
"version": "9.3.0
|
|
5
|
+
"version": "9.3.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"puppeteer"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@browserless/devices": "^9.
|
|
32
|
+
"@browserless/devices": "^9.3.0",
|
|
33
33
|
"@cliqz/adblocker-puppeteer": "~1.23.0",
|
|
34
34
|
"debug-logfmt": "~1.0.4",
|
|
35
35
|
"got": "~11.8.3",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"timeout": "2m",
|
|
69
69
|
"verbose": true
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "489d6fffc2e001fba2961838b73d10f916862676"
|
|
72
72
|
}
|
package/src/engine.bin
CHANGED
|
Binary file
|
package/src/index.js
CHANGED
|
@@ -24,7 +24,6 @@ const engine = PuppeteerBlocker.deserialize(
|
|
|
24
24
|
|
|
25
25
|
engine.on('request-blocked', ({ url }) => debugAdblock('block', url))
|
|
26
26
|
engine.on('request-redirected', ({ url }) => debugAdblock('redirect', url))
|
|
27
|
-
engine.setRequestInterceptionPriority(1)
|
|
28
27
|
|
|
29
28
|
const isEmpty = val => val == null || !(Object.keys(val) || val).length
|
|
30
29
|
|
|
@@ -92,38 +91,38 @@ const disableAnimations = `
|
|
|
92
91
|
}
|
|
93
92
|
`.trim()
|
|
94
93
|
|
|
95
|
-
// related https://github.com/puppeteer/puppeteer/issues/1353
|
|
96
|
-
const createWaitUntilAuto = defaultOpts => (page, opts) => {
|
|
97
|
-
const { timeout } = { ...defaultOpts, ...opts }
|
|
98
|
-
|
|
99
|
-
return Promise.all(
|
|
100
|
-
[
|
|
101
|
-
{
|
|
102
|
-
fn: () => page.waitForNavigation({ waitUntil: 'networkidle2' }),
|
|
103
|
-
debug: 'waitUntilAuto:waitForNavigation'
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
fn: () => page.evaluate(() => window.history.pushState(null, null, null)),
|
|
107
|
-
debug: 'waitUntilAuto:pushState'
|
|
108
|
-
}
|
|
109
|
-
].map(({ fn, ...opts }) => run({ fn: fn(), timeout, ...opts }))
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
94
|
module.exports = ({
|
|
114
95
|
evasions = ALL_EVASIONS_KEYS,
|
|
115
96
|
defaultDevice = 'Macbook Pro 13',
|
|
116
97
|
timeout: globalTimeout,
|
|
117
98
|
...deviceOpts
|
|
118
99
|
}) => {
|
|
119
|
-
const baseTimeout = globalTimeout * (1 / 2)
|
|
120
|
-
const gotoTimeout = timeout * 0.8
|
|
121
|
-
const actionTimeout = baseTimeout * (1 / 8)
|
|
122
|
-
|
|
123
100
|
const getDevice = createDevices(deviceOpts)
|
|
124
101
|
const { viewport: defaultViewport } = getDevice.findDevice(defaultDevice)
|
|
125
102
|
|
|
126
|
-
const
|
|
103
|
+
const timeouts = {
|
|
104
|
+
base: (milliseconds = globalTimeout) => milliseconds * (2 / 3),
|
|
105
|
+
action: (milliseconds = globalTimeout) => milliseconds * (1 / 11),
|
|
106
|
+
goto: (milliseconds = globalTimeout) => milliseconds * (7 / 8)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// related https://github.com/puppeteer/puppeteer/issues/1353
|
|
110
|
+
const _waitUntilAuto = (page, opts = {}) => {
|
|
111
|
+
const timeout = timeouts.action(opts.timeout)
|
|
112
|
+
|
|
113
|
+
return Promise.all(
|
|
114
|
+
[
|
|
115
|
+
{
|
|
116
|
+
fn: () => page.waitForNavigation({ waitUntil: 'networkidle2' }),
|
|
117
|
+
debug: 'waitUntilAuto:waitForNavigation'
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
fn: () => page.evaluate(() => window.history.pushState(null, null, null)),
|
|
121
|
+
debug: 'waitUntilAuto:pushState'
|
|
122
|
+
}
|
|
123
|
+
].map(({ fn, ...opts }) => run({ fn: fn(), timeout, ...opts }))
|
|
124
|
+
)
|
|
125
|
+
}
|
|
127
126
|
|
|
128
127
|
const goto = async (
|
|
129
128
|
page,
|
|
@@ -143,7 +142,7 @@ module.exports = ({
|
|
|
143
142
|
scripts,
|
|
144
143
|
scroll,
|
|
145
144
|
styles,
|
|
146
|
-
timeout =
|
|
145
|
+
timeout = globalTimeout,
|
|
147
146
|
timezone,
|
|
148
147
|
url,
|
|
149
148
|
waitForFunction,
|
|
@@ -155,6 +154,10 @@ module.exports = ({
|
|
|
155
154
|
...args
|
|
156
155
|
}
|
|
157
156
|
) => {
|
|
157
|
+
const baseTimeout = timeouts.base(globalTimeout)
|
|
158
|
+
const actionTimeout = timeouts.action(baseTimeout)
|
|
159
|
+
const gotoTimeout = timeouts.goto(baseTimeout)
|
|
160
|
+
|
|
158
161
|
const isWaitUntilAuto = waitUntil === 'auto'
|
|
159
162
|
if (isWaitUntilAuto) waitUntil = 'load'
|
|
160
163
|
|
|
@@ -163,13 +166,15 @@ module.exports = ({
|
|
|
163
166
|
if (abortTypes.length > 0) {
|
|
164
167
|
await page.setRequestInterception(true)
|
|
165
168
|
page.on('request', req => {
|
|
169
|
+
if (req.isInterceptResolutionHandled()) return
|
|
170
|
+
|
|
166
171
|
const resourceType = req.resourceType()
|
|
167
172
|
if (!abortTypes.includes(resourceType)) {
|
|
168
173
|
debug('continue', { url: req.url(), resourceType })
|
|
169
174
|
return req.continue(req.continueRequestOverrides(), 0)
|
|
170
175
|
}
|
|
171
176
|
debug('abort', { url: req.url(), resourceType })
|
|
172
|
-
return req.abort('blockedbyclient',
|
|
177
|
+
return req.abort('blockedbyclient', 0)
|
|
173
178
|
})
|
|
174
179
|
}
|
|
175
180
|
|
|
@@ -371,7 +376,11 @@ module.exports = ({
|
|
|
371
376
|
|
|
372
377
|
if (click) {
|
|
373
378
|
for (const selector of castArray(click)) {
|
|
374
|
-
await run({
|
|
379
|
+
await run({
|
|
380
|
+
fn: page.click(selector),
|
|
381
|
+
timeout: actionTimeout,
|
|
382
|
+
debug: { click: selector }
|
|
383
|
+
})
|
|
375
384
|
}
|
|
376
385
|
}
|
|
377
386
|
|
|
@@ -396,8 +405,7 @@ module.exports = ({
|
|
|
396
405
|
goto.deviceDescriptors = getDevice.deviceDescriptors
|
|
397
406
|
goto.defaultViewport = defaultViewport
|
|
398
407
|
goto.waitUntilAuto = _waitUntilAuto
|
|
399
|
-
goto.
|
|
400
|
-
goto.actionTimeout = actionTimeout
|
|
408
|
+
goto.timeouts = timeouts
|
|
401
409
|
goto.run = run
|
|
402
410
|
|
|
403
411
|
return goto
|