@browserless/goto 9.3.0-beta.8 → 9.3.2
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 +5 -5
- package/src/engine.bin +0 -0
- package/src/index.js +133 -109
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.
|
|
5
|
+
"version": "9.3.2",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"puppeteer"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@browserless/devices": "^9.
|
|
33
|
-
"@cliqz/adblocker-puppeteer": "~1.23.
|
|
32
|
+
"@browserless/devices": "^9.3.0",
|
|
33
|
+
"@cliqz/adblocker-puppeteer": "~1.23.2",
|
|
34
34
|
"debug-logfmt": "~1.0.4",
|
|
35
35
|
"got": "~11.8.3",
|
|
36
36
|
"is-url-http": "~2.2.5",
|
|
@@ -39,7 +39,7 @@
|
|
|
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.40",
|
|
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": "d5ef2d50041e99e6a4d951eab249bbed157955d4"
|
|
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
|
|
|
@@ -32,7 +31,7 @@ const castArray = value => [].concat(value).filter(Boolean)
|
|
|
32
31
|
|
|
33
32
|
const run = async ({ fn, timeout, debug: props }) => {
|
|
34
33
|
const debugProps = { duration: timeSpan() }
|
|
35
|
-
const result = await pReflect(pTimeout(fn, timeout))
|
|
34
|
+
const result = await pReflect(timeout ? pTimeout(fn, timeout) : fn())
|
|
36
35
|
debugProps.duration = prettyMs(debugProps.duration())
|
|
37
36
|
if (result.isRejected) debugProps.error = result.reason.message || result.reason
|
|
38
37
|
debug(props, debugProps)
|
|
@@ -92,22 +91,85 @@ const disableAnimations = `
|
|
|
92
91
|
}
|
|
93
92
|
`.trim()
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
94
|
+
const inject = async (
|
|
95
|
+
page,
|
|
96
|
+
{ timeout, mediaType, animations, hide, remove, modules, scripts, styles }
|
|
97
|
+
) => {
|
|
98
|
+
const postPromises = []
|
|
99
|
+
|
|
100
|
+
if (mediaType) {
|
|
101
|
+
postPromises.push(
|
|
102
|
+
run({
|
|
103
|
+
fn: page.emulateMediaType(mediaType),
|
|
104
|
+
timeout,
|
|
105
|
+
debug: { mediaType }
|
|
106
|
+
})
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (animations === false) {
|
|
111
|
+
postPromises.push(
|
|
112
|
+
run({
|
|
113
|
+
fn: injectStyle(page, disableAnimations),
|
|
114
|
+
timeout,
|
|
115
|
+
debug: 'disableAnimations'
|
|
116
|
+
})
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (hide) {
|
|
121
|
+
postPromises.push(
|
|
122
|
+
run({
|
|
123
|
+
fn: injectStyle(page, `${castArray(hide).join(', ')} { visibility: hidden !important; }`),
|
|
124
|
+
timeout,
|
|
125
|
+
debug: 'hide'
|
|
126
|
+
})
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (remove) {
|
|
131
|
+
postPromises.push(
|
|
132
|
+
run({
|
|
133
|
+
fn: injectStyle(page, `${castArray(remove).join(', ')} { display: none !important; }`),
|
|
134
|
+
timeout,
|
|
135
|
+
debug: 'remove'
|
|
136
|
+
})
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (modules) {
|
|
141
|
+
postPromises.push(
|
|
142
|
+
run({
|
|
143
|
+
fn: Promise.all(
|
|
144
|
+
castArray(modules).map(value => injectScript(page, value, { type: 'modules' }))
|
|
145
|
+
),
|
|
146
|
+
timeout,
|
|
147
|
+
debug: 'modules'
|
|
148
|
+
})
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (scripts) {
|
|
153
|
+
postPromises.push(
|
|
154
|
+
run({
|
|
155
|
+
fn: Promise.all(castArray(scripts).map(value => injectScript(page, value))),
|
|
156
|
+
timeout,
|
|
157
|
+
debug: 'scripts'
|
|
158
|
+
})
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (styles) {
|
|
163
|
+
postPromises.push(
|
|
164
|
+
run({
|
|
165
|
+
fn: Promise.all(castArray(styles).map(style => injectStyle(page, style))),
|
|
166
|
+
timeout,
|
|
167
|
+
debug: 'styles'
|
|
168
|
+
})
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return Promise.all(postPromises)
|
|
111
173
|
}
|
|
112
174
|
|
|
113
175
|
module.exports = ({
|
|
@@ -116,13 +178,32 @@ module.exports = ({
|
|
|
116
178
|
timeout: globalTimeout,
|
|
117
179
|
...deviceOpts
|
|
118
180
|
}) => {
|
|
119
|
-
const baseTimeout = globalTimeout * (1 / 2)
|
|
120
|
-
const actionTimeout = baseTimeout * (1 / 8)
|
|
121
|
-
|
|
122
181
|
const getDevice = createDevices(deviceOpts)
|
|
123
182
|
const { viewport: defaultViewport } = getDevice.findDevice(defaultDevice)
|
|
124
183
|
|
|
125
|
-
const
|
|
184
|
+
const timeouts = {
|
|
185
|
+
base: (milliseconds = globalTimeout) => milliseconds * (2 / 3),
|
|
186
|
+
action: (milliseconds = globalTimeout) => milliseconds * (1 / 11),
|
|
187
|
+
goto: (milliseconds = globalTimeout) => milliseconds * (7 / 8)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// related https://github.com/puppeteer/puppeteer/issues/1353
|
|
191
|
+
const _waitUntilAuto = (page, opts = {}) => {
|
|
192
|
+
const timeout = timeouts.action(opts.timeout)
|
|
193
|
+
|
|
194
|
+
return Promise.all(
|
|
195
|
+
[
|
|
196
|
+
{
|
|
197
|
+
fn: () => page.waitForNavigation({ waitUntil: 'networkidle2' }),
|
|
198
|
+
debug: 'waitUntilAuto:waitForNavigation'
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
fn: () => page.evaluate(() => window.history.pushState(null, null, null)),
|
|
202
|
+
debug: 'waitUntilAuto:pushState'
|
|
203
|
+
}
|
|
204
|
+
].map(({ fn, ...opts }) => run({ fn: fn(), timeout, ...opts }))
|
|
205
|
+
)
|
|
206
|
+
}
|
|
126
207
|
|
|
127
208
|
const goto = async (
|
|
128
209
|
page,
|
|
@@ -142,7 +223,7 @@ module.exports = ({
|
|
|
142
223
|
scripts,
|
|
143
224
|
scroll,
|
|
144
225
|
styles,
|
|
145
|
-
timeout =
|
|
226
|
+
timeout = globalTimeout,
|
|
146
227
|
timezone,
|
|
147
228
|
url,
|
|
148
229
|
waitForFunction,
|
|
@@ -154,6 +235,10 @@ module.exports = ({
|
|
|
154
235
|
...args
|
|
155
236
|
}
|
|
156
237
|
) => {
|
|
238
|
+
const baseTimeout = timeouts.base(globalTimeout)
|
|
239
|
+
const actionTimeout = timeouts.action(baseTimeout)
|
|
240
|
+
const gotoTimeout = timeouts.goto(baseTimeout)
|
|
241
|
+
|
|
157
242
|
const isWaitUntilAuto = waitUntil === 'auto'
|
|
158
243
|
if (isWaitUntilAuto) waitUntil = 'load'
|
|
159
244
|
|
|
@@ -162,13 +247,15 @@ module.exports = ({
|
|
|
162
247
|
if (abortTypes.length > 0) {
|
|
163
248
|
await page.setRequestInterception(true)
|
|
164
249
|
page.on('request', req => {
|
|
250
|
+
if (req.isInterceptResolutionHandled()) return
|
|
251
|
+
|
|
165
252
|
const resourceType = req.resourceType()
|
|
166
253
|
if (!abortTypes.includes(resourceType)) {
|
|
167
254
|
debug('continue', { url: req.url(), resourceType })
|
|
168
255
|
return req.continue(req.continueRequestOverrides(), 0)
|
|
169
256
|
}
|
|
170
257
|
debug('abort', { url: req.url(), resourceType })
|
|
171
|
-
return req.abort('blockedbyclient',
|
|
258
|
+
return req.abort('blockedbyclient', 0)
|
|
172
259
|
})
|
|
173
260
|
}
|
|
174
261
|
|
|
@@ -275,9 +362,9 @@ module.exports = ({
|
|
|
275
362
|
|
|
276
363
|
await Promise.all(prePromises.concat(applyEvasions))
|
|
277
364
|
|
|
278
|
-
const { value } = await run({
|
|
365
|
+
const { value: response } = await run({
|
|
279
366
|
fn: html ? page.setContent(html, args) : page.goto(url, args),
|
|
280
|
-
timeout:
|
|
367
|
+
timeout: gotoTimeout,
|
|
281
368
|
debug: html ? 'html' : 'url'
|
|
282
369
|
})
|
|
283
370
|
|
|
@@ -288,89 +375,28 @@ module.exports = ({
|
|
|
288
375
|
waitForTimeout
|
|
289
376
|
})) {
|
|
290
377
|
if (value) {
|
|
291
|
-
await run({ fn: page[key](value), timeout:
|
|
378
|
+
await run({ fn: page[key](value), timeout: gotoTimeout, debug: { [key]: value } })
|
|
292
379
|
}
|
|
293
380
|
}
|
|
294
381
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (animations === false) {
|
|
308
|
-
postPromises.push(
|
|
309
|
-
run({
|
|
310
|
-
fn: injectStyle(page, disableAnimations),
|
|
311
|
-
timeout: actionTimeout,
|
|
312
|
-
debug: 'disableAnimations'
|
|
313
|
-
})
|
|
314
|
-
)
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
if (hide) {
|
|
318
|
-
postPromises.push(
|
|
319
|
-
run({
|
|
320
|
-
fn: injectStyle(page, `${castArray(hide).join(', ')} { visibility: hidden !important; }`),
|
|
321
|
-
timeout: actionTimeout,
|
|
322
|
-
debug: 'hide'
|
|
323
|
-
})
|
|
324
|
-
)
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (remove) {
|
|
328
|
-
postPromises.push(
|
|
329
|
-
run({
|
|
330
|
-
fn: injectStyle(page, `${castArray(remove).join(', ')} { display: none !important; }`),
|
|
331
|
-
timeout: actionTimeout,
|
|
332
|
-
debug: 'remove'
|
|
333
|
-
})
|
|
334
|
-
)
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (modules) {
|
|
338
|
-
postPromises.push(
|
|
339
|
-
run({
|
|
340
|
-
fn: Promise.all(
|
|
341
|
-
castArray(modules).map(value => injectScript(page, value, { type: 'modules' }))
|
|
342
|
-
),
|
|
343
|
-
timeout: actionTimeout,
|
|
344
|
-
debug: 'modules'
|
|
345
|
-
})
|
|
346
|
-
)
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (scripts) {
|
|
350
|
-
postPromises.push(
|
|
351
|
-
run({
|
|
352
|
-
fn: Promise.all(castArray(scripts).map(value => injectScript(page, value))),
|
|
353
|
-
timeout: actionTimeout,
|
|
354
|
-
debug: 'scripts'
|
|
355
|
-
})
|
|
356
|
-
)
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (styles) {
|
|
360
|
-
postPromises.push(
|
|
361
|
-
run({
|
|
362
|
-
fn: Promise.all(castArray(styles).map(style => injectStyle(page, style))),
|
|
363
|
-
timeout: actionTimeout,
|
|
364
|
-
debug: 'styles'
|
|
365
|
-
})
|
|
366
|
-
)
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
await Promise.all(postPromises)
|
|
382
|
+
await inject(page, {
|
|
383
|
+
timeout: actionTimeout,
|
|
384
|
+
mediaType,
|
|
385
|
+
animations,
|
|
386
|
+
hide,
|
|
387
|
+
remove,
|
|
388
|
+
modules,
|
|
389
|
+
scripts,
|
|
390
|
+
styles
|
|
391
|
+
})
|
|
370
392
|
|
|
371
393
|
if (click) {
|
|
372
394
|
for (const selector of castArray(click)) {
|
|
373
|
-
await run({
|
|
395
|
+
await run({
|
|
396
|
+
fn: page.click(selector),
|
|
397
|
+
timeout: actionTimeout,
|
|
398
|
+
debug: { click: selector }
|
|
399
|
+
})
|
|
374
400
|
}
|
|
375
401
|
}
|
|
376
402
|
|
|
@@ -383,10 +409,10 @@ module.exports = ({
|
|
|
383
409
|
}
|
|
384
410
|
|
|
385
411
|
if (isWaitUntilAuto) {
|
|
386
|
-
await waitUntilAuto(page, { response
|
|
412
|
+
await waitUntilAuto(page, { response, timeout: actionTimeout * 2 })
|
|
387
413
|
}
|
|
388
414
|
|
|
389
|
-
return { response
|
|
415
|
+
return { response, device }
|
|
390
416
|
}
|
|
391
417
|
|
|
392
418
|
goto.getDevice = getDevice
|
|
@@ -395,14 +421,12 @@ module.exports = ({
|
|
|
395
421
|
goto.deviceDescriptors = getDevice.deviceDescriptors
|
|
396
422
|
goto.defaultViewport = defaultViewport
|
|
397
423
|
goto.waitUntilAuto = _waitUntilAuto
|
|
398
|
-
goto.
|
|
399
|
-
goto.actionTimeout = actionTimeout
|
|
424
|
+
goto.timeouts = timeouts
|
|
400
425
|
goto.run = run
|
|
401
426
|
|
|
402
427
|
return goto
|
|
403
428
|
}
|
|
404
429
|
|
|
405
430
|
module.exports.parseCookies = parseCookies
|
|
406
|
-
module.exports.
|
|
407
|
-
module.exports.injectStyle = injectStyle
|
|
431
|
+
module.exports.inject = inject
|
|
408
432
|
module.exports.evasions = ALL_EVASIONS_KEYS
|