@browserless/goto 9.2.6 → 9.2.19
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 +2 -2
- package/src/engine.bin +0 -0
- package/src/index.js +121 -79
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.2.
|
|
5
|
+
"version": "9.2.19",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"timeout": "2m",
|
|
69
69
|
"verbose": true
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "e44bfcf5f5ead8f42ad758c200b8fc5c1be4a761"
|
|
72
72
|
}
|
package/src/engine.bin
CHANGED
|
Binary file
|
package/src/index.js
CHANGED
|
@@ -29,15 +29,14 @@ const isEmpty = val => val == null || !(Object.keys(val) || val).length
|
|
|
29
29
|
|
|
30
30
|
const castArray = value => [].concat(value).filter(Boolean)
|
|
31
31
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
32
|
+
const run = async ({ fn, timeout, debug: props }) => {
|
|
33
|
+
const debugProps = { duration: timeSpan() }
|
|
34
|
+
const result = await pReflect(pTimeout(fn, timeout))
|
|
35
|
+
debugProps.duration = prettyMs(debugProps.duration())
|
|
36
|
+
if (result.isRejected) debugProps.error = result.reason.message || result.reason
|
|
37
|
+
debug(props, debugProps)
|
|
38
|
+
return result
|
|
39
|
+
}
|
|
41
40
|
|
|
42
41
|
const parseCookies = (url, str) =>
|
|
43
42
|
str.split(';').reduce((acc, cookieStr) => {
|
|
@@ -66,28 +65,19 @@ const getMediaFeatures = ({ animations, colorScheme }) => {
|
|
|
66
65
|
return prefers
|
|
67
66
|
}
|
|
68
67
|
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
[getInjectKey('js', value)]: value,
|
|
75
|
-
...attributes
|
|
76
|
-
})
|
|
77
|
-
)
|
|
78
|
-
)
|
|
79
|
-
)
|
|
68
|
+
const injectScript = (page, value, attributes) =>
|
|
69
|
+
page.addScriptTag({
|
|
70
|
+
[getInjectKey('js', value)]: value,
|
|
71
|
+
...attributes
|
|
72
|
+
})
|
|
80
73
|
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
)
|
|
89
|
-
)
|
|
90
|
-
)
|
|
74
|
+
const injectStyle = (page, style) =>
|
|
75
|
+
page.addStyleTag({
|
|
76
|
+
[getInjectKey('css', style)]: style
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const getInjectKey = (ext, value) =>
|
|
80
|
+
isUrl(value) ? 'url' : value.endsWith(`.${ext}`) ? 'path' : 'content'
|
|
91
81
|
|
|
92
82
|
const disableAnimations = `
|
|
93
83
|
*,
|
|
@@ -101,29 +91,22 @@ const disableAnimations = `
|
|
|
101
91
|
}
|
|
102
92
|
`.trim()
|
|
103
93
|
|
|
104
|
-
const run = async ({ fn, debug: props }) => {
|
|
105
|
-
const debugProps = { duration: timeSpan() }
|
|
106
|
-
const result = await pReflect(fn)
|
|
107
|
-
debugProps.duration = prettyMs(debugProps.duration())
|
|
108
|
-
if (result.isRejected) debugProps.error = result.reason.message || result.reason
|
|
109
|
-
debug(props, debugProps)
|
|
110
|
-
return result
|
|
111
|
-
}
|
|
112
|
-
|
|
113
94
|
// related https://github.com/puppeteer/puppeteer/issues/1353
|
|
114
95
|
const createWaitUntilAuto = defaultOpts => (page, opts) => {
|
|
115
96
|
const { timeout } = { ...defaultOpts, ...opts }
|
|
116
97
|
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
page.waitForNavigation({ waitUntil: 'networkidle2' }),
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
98
|
+
return Promise.all(
|
|
99
|
+
[
|
|
100
|
+
{
|
|
101
|
+
fn: () => page.waitForNavigation({ waitUntil: 'networkidle2' }),
|
|
102
|
+
debug: 'waitUntilAuto:waitForNavigation'
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
fn: () => page.evaluate(() => window.history.pushState(null, null, null)),
|
|
106
|
+
debug: 'waitUntilAuto:pushState'
|
|
107
|
+
}
|
|
108
|
+
].map(({ fn, ...opts }) => run({ fn: fn(), timeout, ...opts }))
|
|
109
|
+
)
|
|
127
110
|
}
|
|
128
111
|
|
|
129
112
|
module.exports = ({
|
|
@@ -133,14 +116,12 @@ module.exports = ({
|
|
|
133
116
|
...deviceOpts
|
|
134
117
|
}) => {
|
|
135
118
|
const baseTimeout = globalTimeout * (1 / 2)
|
|
119
|
+
const actionTimeout = baseTimeout * (1 / 8)
|
|
120
|
+
|
|
136
121
|
const getDevice = createDevices(deviceOpts)
|
|
137
122
|
const { viewport: defaultViewport } = getDevice.findDevice(defaultDevice)
|
|
138
123
|
|
|
139
|
-
const
|
|
140
|
-
.filter(Boolean)
|
|
141
|
-
.reduce((acc, key) => [...acc, EVASIONS[key]], [])
|
|
142
|
-
|
|
143
|
-
const _waitUntilAuto = createWaitUntilAuto({ timeout: baseTimeout })
|
|
124
|
+
const _waitUntilAuto = createWaitUntilAuto({ timeout: actionTimeout })
|
|
144
125
|
|
|
145
126
|
const goto = async (
|
|
146
127
|
page,
|
|
@@ -178,13 +159,20 @@ module.exports = ({
|
|
|
178
159
|
const prePromises = []
|
|
179
160
|
|
|
180
161
|
if (adblock) {
|
|
181
|
-
prePromises.push(
|
|
162
|
+
prePromises.push(
|
|
163
|
+
run({
|
|
164
|
+
fn: engine.enableBlockingInPage(page),
|
|
165
|
+
timeout: actionTimeout,
|
|
166
|
+
debug: 'adblock'
|
|
167
|
+
})
|
|
168
|
+
)
|
|
182
169
|
}
|
|
183
170
|
|
|
184
171
|
if (javascript === false) {
|
|
185
172
|
prePromises.push(
|
|
186
173
|
run({
|
|
187
174
|
fn: page.setJavaScriptEnabled(false),
|
|
175
|
+
timeout: actionTimeout,
|
|
188
176
|
debug: { javascript }
|
|
189
177
|
})
|
|
190
178
|
)
|
|
@@ -200,6 +188,7 @@ module.exports = ({
|
|
|
200
188
|
prePromises.push(
|
|
201
189
|
run({
|
|
202
190
|
fn: page.setViewport(device.viewport),
|
|
191
|
+
timeout: actionTimeout,
|
|
203
192
|
debug: 'viewport'
|
|
204
193
|
})
|
|
205
194
|
)
|
|
@@ -213,6 +202,7 @@ module.exports = ({
|
|
|
213
202
|
prePromises.push(
|
|
214
203
|
run({
|
|
215
204
|
fn: page.setCookie(...cookies),
|
|
205
|
+
timeout: actionTimeout,
|
|
216
206
|
debug: ['cookies', ...cookies.map(({ name }) => name)]
|
|
217
207
|
})
|
|
218
208
|
)
|
|
@@ -222,6 +212,7 @@ module.exports = ({
|
|
|
222
212
|
prePromises.push(
|
|
223
213
|
run({
|
|
224
214
|
fn: page.setUserAgent(headers['user-agent']),
|
|
215
|
+
timeout: actionTimeout,
|
|
225
216
|
debug: { 'user-agent': headers['user-agent'] }
|
|
226
217
|
})
|
|
227
218
|
)
|
|
@@ -230,6 +221,7 @@ module.exports = ({
|
|
|
230
221
|
prePromises.push(
|
|
231
222
|
run({
|
|
232
223
|
fn: page.setExtraHTTPHeaders(headers),
|
|
224
|
+
timeout: actionTimeout,
|
|
233
225
|
debug: { headers: headersKeys }
|
|
234
226
|
})
|
|
235
227
|
)
|
|
@@ -239,6 +231,7 @@ module.exports = ({
|
|
|
239
231
|
prePromises.push(
|
|
240
232
|
run({
|
|
241
233
|
fn: page.emulateMediaType(mediaType),
|
|
234
|
+
timeout: actionTimeout,
|
|
242
235
|
debug: { mediaType }
|
|
243
236
|
})
|
|
244
237
|
)
|
|
@@ -248,6 +241,7 @@ module.exports = ({
|
|
|
248
241
|
prePromises.push(
|
|
249
242
|
run({
|
|
250
243
|
fn: page.emulateTimezone(timezone),
|
|
244
|
+
timeout: actionTimeout,
|
|
251
245
|
debug: { timezone }
|
|
252
246
|
})
|
|
253
247
|
)
|
|
@@ -259,12 +253,23 @@ module.exports = ({
|
|
|
259
253
|
prePromises.push(
|
|
260
254
|
run({
|
|
261
255
|
fn: page.emulateMediaFeatures(mediaFeatures),
|
|
262
|
-
|
|
256
|
+
timeout: actionTimeout,
|
|
257
|
+
debug: { mediaFeatures: mediaFeatures.map(({ name }) => name) }
|
|
263
258
|
})
|
|
264
259
|
)
|
|
265
260
|
}
|
|
266
261
|
|
|
267
|
-
|
|
262
|
+
const applyEvasions = castArray(evasions)
|
|
263
|
+
.filter(Boolean)
|
|
264
|
+
.map(key =>
|
|
265
|
+
run({
|
|
266
|
+
fn: EVASIONS[key](page),
|
|
267
|
+
timeout: actionTimeout,
|
|
268
|
+
debug: key
|
|
269
|
+
})
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
await Promise.all(prePromises.concat(applyEvasions))
|
|
268
273
|
|
|
269
274
|
if (abortTypes.length > 0) {
|
|
270
275
|
await page.setRequestInterception(true)
|
|
@@ -277,7 +282,8 @@ module.exports = ({
|
|
|
277
282
|
}
|
|
278
283
|
|
|
279
284
|
const { value } = await run({
|
|
280
|
-
fn:
|
|
285
|
+
fn: html ? page.setContent(html, args) : page.goto(url, args),
|
|
286
|
+
timeout,
|
|
281
287
|
debug: html ? 'html' : 'url'
|
|
282
288
|
})
|
|
283
289
|
|
|
@@ -287,40 +293,71 @@ module.exports = ({
|
|
|
287
293
|
waitForFunction,
|
|
288
294
|
waitForTimeout
|
|
289
295
|
})) {
|
|
290
|
-
if (value)
|
|
296
|
+
if (value) {
|
|
297
|
+
await run({ fn: page[key](value), timeout: actionTimeout, debug: { [key]: value } })
|
|
298
|
+
}
|
|
291
299
|
}
|
|
292
300
|
|
|
293
301
|
const postPromises = []
|
|
294
302
|
|
|
295
303
|
if (animations === false) {
|
|
296
|
-
postPromises.push(
|
|
304
|
+
postPromises.push(
|
|
305
|
+
run({
|
|
306
|
+
fn: injectStyle(page, disableAnimations),
|
|
307
|
+
timeout: actionTimeout,
|
|
308
|
+
debug: 'disableAnimations'
|
|
309
|
+
})
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (hide) {
|
|
314
|
+
postPromises.push(
|
|
315
|
+
run({
|
|
316
|
+
fn: injectStyle(page, `${castArray(hide).join(', ')} { visibility: hidden !important; }`),
|
|
317
|
+
timeout: actionTimeout,
|
|
318
|
+
debug: 'hide'
|
|
319
|
+
})
|
|
320
|
+
)
|
|
297
321
|
}
|
|
298
322
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
323
|
+
if (remove) {
|
|
324
|
+
postPromises.push(
|
|
325
|
+
run({
|
|
326
|
+
fn: injectStyle(page, `${castArray(remove).join(', ')} { display: none !important; }`),
|
|
327
|
+
timeout: actionTimeout,
|
|
328
|
+
debug: 'remove'
|
|
329
|
+
})
|
|
330
|
+
)
|
|
331
|
+
}
|
|
303
332
|
|
|
304
|
-
if (
|
|
333
|
+
if (modules) {
|
|
305
334
|
postPromises.push(
|
|
306
335
|
run({
|
|
307
|
-
fn: Promise.all(
|
|
308
|
-
|
|
336
|
+
fn: Promise.all(
|
|
337
|
+
castArray(modules).map(value => injectScript(page, value, { type: 'modules' }))
|
|
338
|
+
),
|
|
339
|
+
timeout: actionTimeout,
|
|
340
|
+
debug: 'modules'
|
|
309
341
|
})
|
|
310
342
|
)
|
|
311
343
|
}
|
|
312
344
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
345
|
+
if (scripts) {
|
|
346
|
+
postPromises.push(
|
|
347
|
+
run({
|
|
348
|
+
fn: Promise.all(castArray(scripts).map(value => injectScript(page, value))),
|
|
349
|
+
timeout: actionTimeout,
|
|
350
|
+
debug: 'scripts'
|
|
351
|
+
})
|
|
352
|
+
)
|
|
353
|
+
}
|
|
318
354
|
|
|
319
|
-
if (
|
|
355
|
+
if (styles) {
|
|
320
356
|
postPromises.push(
|
|
321
357
|
run({
|
|
322
|
-
fn: Promise.all(
|
|
323
|
-
|
|
358
|
+
fn: Promise.all(castArray(styles).map(style => injectStyle(page, style))),
|
|
359
|
+
timeout: actionTimeout,
|
|
360
|
+
debug: 'styles'
|
|
324
361
|
})
|
|
325
362
|
)
|
|
326
363
|
}
|
|
@@ -329,18 +366,21 @@ module.exports = ({
|
|
|
329
366
|
|
|
330
367
|
if (click) {
|
|
331
368
|
for (const selector of castArray(click)) {
|
|
332
|
-
await run({ fn: page.click(selector), debug: { click: selector } })
|
|
369
|
+
await run({ fn: page.click(selector), timeout: actionTimeout, debug: { click: selector } })
|
|
333
370
|
}
|
|
334
371
|
}
|
|
335
372
|
|
|
336
373
|
if (scroll) {
|
|
337
374
|
await run({
|
|
338
375
|
fn: page.$eval(scroll, el => el.scrollIntoView()),
|
|
376
|
+
timeout: actionTimeout,
|
|
339
377
|
debug: { scroll }
|
|
340
378
|
})
|
|
341
379
|
}
|
|
342
380
|
|
|
343
|
-
if (isWaitUntilAuto)
|
|
381
|
+
if (isWaitUntilAuto) {
|
|
382
|
+
await waitUntilAuto(page, { response: value, timeout: actionTimeout * 2 })
|
|
383
|
+
}
|
|
344
384
|
|
|
345
385
|
return { response: value, device }
|
|
346
386
|
}
|
|
@@ -352,11 +392,13 @@ module.exports = ({
|
|
|
352
392
|
goto.defaultViewport = defaultViewport
|
|
353
393
|
goto.waitUntilAuto = _waitUntilAuto
|
|
354
394
|
goto.timeout = baseTimeout
|
|
395
|
+
goto.actionTimeout = actionTimeout
|
|
396
|
+
goto.run = run
|
|
355
397
|
|
|
356
398
|
return goto
|
|
357
399
|
}
|
|
358
400
|
|
|
359
401
|
module.exports.parseCookies = parseCookies
|
|
360
|
-
module.exports.
|
|
361
|
-
module.exports.
|
|
402
|
+
module.exports.injectScript = injectScript
|
|
403
|
+
module.exports.injectStyle = injectStyle
|
|
362
404
|
module.exports.evasions = ALL_EVASIONS_KEYS
|