@browserless/goto 9.2.21 → 9.3.0-beta.12
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 +6 -6
- package/src/engine.bin +0 -0
- package/src/index.js +50 -41
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.
|
|
5
|
+
"version": "9.3.0-beta.12",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
"puppeteer"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@browserless/devices": "^9.
|
|
32
|
+
"@browserless/devices": "^9.3.0-beta.12",
|
|
33
33
|
"@cliqz/adblocker-puppeteer": "~1.23.0",
|
|
34
34
|
"debug-logfmt": "~1.0.4",
|
|
35
|
-
"got": "~11.8.
|
|
36
|
-
"is-url-http": "~2.2.
|
|
35
|
+
"got": "~11.8.3",
|
|
36
|
+
"is-url-http": "~2.2.5",
|
|
37
37
|
"p-reflect": "~2.1.0",
|
|
38
38
|
"p-timeout": "~4.1.0",
|
|
39
39
|
"pretty-ms": "~7.0.1",
|
|
40
40
|
"shallow-equal": "~1.2.1",
|
|
41
41
|
"time-span": "~4.0.0",
|
|
42
|
-
"top-user-agents": "~1.0.
|
|
42
|
+
"top-user-agents": "~1.0.39",
|
|
43
43
|
"tough-cookie": "~4.0.0",
|
|
44
44
|
"unique-random-array": "~2.0.0"
|
|
45
45
|
},
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"timeout": "2m",
|
|
69
69
|
"verbose": true
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "4c4e979c675f544b903ee5c0d6add9a8651deb0c"
|
|
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,37 +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 actionTimeout = baseTimeout * (1 / 8)
|
|
121
|
-
|
|
122
100
|
const getDevice = createDevices(deviceOpts)
|
|
123
101
|
const { viewport: defaultViewport } = getDevice.findDevice(defaultDevice)
|
|
124
102
|
|
|
125
|
-
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
|
+
}
|
|
126
126
|
|
|
127
127
|
const goto = async (
|
|
128
128
|
page,
|
|
@@ -142,7 +142,7 @@ module.exports = ({
|
|
|
142
142
|
scripts,
|
|
143
143
|
scroll,
|
|
144
144
|
styles,
|
|
145
|
-
timeout =
|
|
145
|
+
timeout = globalTimeout,
|
|
146
146
|
timezone,
|
|
147
147
|
url,
|
|
148
148
|
waitForFunction,
|
|
@@ -154,6 +154,10 @@ module.exports = ({
|
|
|
154
154
|
...args
|
|
155
155
|
}
|
|
156
156
|
) => {
|
|
157
|
+
const baseTimeout = timeouts.base(globalTimeout)
|
|
158
|
+
const actionTimeout = timeouts.action(baseTimeout)
|
|
159
|
+
const gotoTimeout = timeouts.goto(baseTimeout)
|
|
160
|
+
|
|
157
161
|
const isWaitUntilAuto = waitUntil === 'auto'
|
|
158
162
|
if (isWaitUntilAuto) waitUntil = 'load'
|
|
159
163
|
|
|
@@ -162,13 +166,15 @@ module.exports = ({
|
|
|
162
166
|
if (abortTypes.length > 0) {
|
|
163
167
|
await page.setRequestInterception(true)
|
|
164
168
|
page.on('request', req => {
|
|
169
|
+
if (req.isInterceptResolutionHandled()) return
|
|
170
|
+
|
|
165
171
|
const resourceType = req.resourceType()
|
|
166
172
|
if (!abortTypes.includes(resourceType)) {
|
|
167
173
|
debug('continue', { url: req.url(), resourceType })
|
|
168
|
-
return req.continue(req.continueRequestOverrides(),
|
|
174
|
+
return req.continue(req.continueRequestOverrides(), 0)
|
|
169
175
|
}
|
|
170
176
|
debug('abort', { url: req.url(), resourceType })
|
|
171
|
-
return req.abort('blockedbyclient',
|
|
177
|
+
return req.abort('blockedbyclient', 0)
|
|
172
178
|
})
|
|
173
179
|
}
|
|
174
180
|
|
|
@@ -241,16 +247,6 @@ module.exports = ({
|
|
|
241
247
|
)
|
|
242
248
|
}
|
|
243
249
|
|
|
244
|
-
if (mediaType) {
|
|
245
|
-
prePromises.push(
|
|
246
|
-
run({
|
|
247
|
-
fn: page.emulateMediaType(mediaType),
|
|
248
|
-
timeout: actionTimeout,
|
|
249
|
-
debug: { mediaType }
|
|
250
|
-
})
|
|
251
|
-
)
|
|
252
|
-
}
|
|
253
|
-
|
|
254
250
|
if (timezone) {
|
|
255
251
|
prePromises.push(
|
|
256
252
|
run({
|
|
@@ -287,7 +283,7 @@ module.exports = ({
|
|
|
287
283
|
|
|
288
284
|
const { value } = await run({
|
|
289
285
|
fn: html ? page.setContent(html, args) : page.goto(url, args),
|
|
290
|
-
timeout,
|
|
286
|
+
timeout: gotoTimeout,
|
|
291
287
|
debug: html ? 'html' : 'url'
|
|
292
288
|
})
|
|
293
289
|
|
|
@@ -298,12 +294,22 @@ module.exports = ({
|
|
|
298
294
|
waitForTimeout
|
|
299
295
|
})) {
|
|
300
296
|
if (value) {
|
|
301
|
-
await run({ fn: page[key](value), timeout:
|
|
297
|
+
await run({ fn: page[key](value), timeout: gotoTimeout, debug: { [key]: value } })
|
|
302
298
|
}
|
|
303
299
|
}
|
|
304
300
|
|
|
305
301
|
const postPromises = []
|
|
306
302
|
|
|
303
|
+
if (mediaType) {
|
|
304
|
+
postPromises.push(
|
|
305
|
+
run({
|
|
306
|
+
fn: page.emulateMediaType(mediaType),
|
|
307
|
+
timeout: actionTimeout,
|
|
308
|
+
debug: { mediaType }
|
|
309
|
+
})
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
|
|
307
313
|
if (animations === false) {
|
|
308
314
|
postPromises.push(
|
|
309
315
|
run({
|
|
@@ -370,7 +376,11 @@ module.exports = ({
|
|
|
370
376
|
|
|
371
377
|
if (click) {
|
|
372
378
|
for (const selector of castArray(click)) {
|
|
373
|
-
await run({
|
|
379
|
+
await run({
|
|
380
|
+
fn: page.click(selector),
|
|
381
|
+
timeout: actionTimeout,
|
|
382
|
+
debug: { click: selector }
|
|
383
|
+
})
|
|
374
384
|
}
|
|
375
385
|
}
|
|
376
386
|
|
|
@@ -395,8 +405,7 @@ module.exports = ({
|
|
|
395
405
|
goto.deviceDescriptors = getDevice.deviceDescriptors
|
|
396
406
|
goto.defaultViewport = defaultViewport
|
|
397
407
|
goto.waitUntilAuto = _waitUntilAuto
|
|
398
|
-
goto.
|
|
399
|
-
goto.actionTimeout = actionTimeout
|
|
408
|
+
goto.timeouts = timeouts
|
|
400
409
|
goto.run = run
|
|
401
410
|
|
|
402
411
|
return goto
|