@browserless/goto 9.2.22 → 9.3.0-beta.10
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 +46 -39
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.10",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"@browserless/devices": "^9.2.22",
|
|
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": "195f7c7c39a4f04e74c2e4cd1b4c45bb4dec6166"
|
|
72
72
|
}
|
package/src/engine.bin
CHANGED
|
Binary file
|
package/src/index.js
CHANGED
|
@@ -92,37 +92,38 @@ const disableAnimations = `
|
|
|
92
92
|
}
|
|
93
93
|
`.trim()
|
|
94
94
|
|
|
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
95
|
module.exports = ({
|
|
114
96
|
evasions = ALL_EVASIONS_KEYS,
|
|
115
97
|
defaultDevice = 'Macbook Pro 13',
|
|
116
98
|
timeout: globalTimeout,
|
|
117
99
|
...deviceOpts
|
|
118
100
|
}) => {
|
|
119
|
-
const baseTimeout = globalTimeout * (1 / 2)
|
|
120
|
-
const actionTimeout = baseTimeout * (1 / 8)
|
|
121
|
-
|
|
122
101
|
const getDevice = createDevices(deviceOpts)
|
|
123
102
|
const { viewport: defaultViewport } = getDevice.findDevice(defaultDevice)
|
|
124
103
|
|
|
125
|
-
const
|
|
104
|
+
const timeouts = {
|
|
105
|
+
base: (milliseconds = globalTimeout) => milliseconds * (1 / 2),
|
|
106
|
+
action: (milliseconds = globalTimeout) => milliseconds * (1 / 8),
|
|
107
|
+
goto: (milliseconds = globalTimeout) => milliseconds * 0.8
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// related https://github.com/puppeteer/puppeteer/issues/1353
|
|
111
|
+
const _waitUntilAuto = (page, opts = {}) => {
|
|
112
|
+
const timeout = timeouts.action(opts.timeout)
|
|
113
|
+
|
|
114
|
+
return Promise.all(
|
|
115
|
+
[
|
|
116
|
+
{
|
|
117
|
+
fn: () => page.waitForNavigation({ waitUntil: 'networkidle2' }),
|
|
118
|
+
debug: 'waitUntilAuto:waitForNavigation'
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
fn: () => page.evaluate(() => window.history.pushState(null, null, null)),
|
|
122
|
+
debug: 'waitUntilAuto:pushState'
|
|
123
|
+
}
|
|
124
|
+
].map(({ fn, ...opts }) => run({ fn: fn(), timeout, ...opts }))
|
|
125
|
+
)
|
|
126
|
+
}
|
|
126
127
|
|
|
127
128
|
const goto = async (
|
|
128
129
|
page,
|
|
@@ -142,7 +143,7 @@ module.exports = ({
|
|
|
142
143
|
scripts,
|
|
143
144
|
scroll,
|
|
144
145
|
styles,
|
|
145
|
-
timeout =
|
|
146
|
+
timeout = timeouts.base(globalTimeout),
|
|
146
147
|
timezone,
|
|
147
148
|
url,
|
|
148
149
|
waitForFunction,
|
|
@@ -154,6 +155,9 @@ module.exports = ({
|
|
|
154
155
|
...args
|
|
155
156
|
}
|
|
156
157
|
) => {
|
|
158
|
+
const actionTimeout = timeouts.action(timeout)
|
|
159
|
+
const gotoTimeout = timeouts.goto(timeout)
|
|
160
|
+
|
|
157
161
|
const isWaitUntilAuto = waitUntil === 'auto'
|
|
158
162
|
if (isWaitUntilAuto) waitUntil = 'load'
|
|
159
163
|
|
|
@@ -165,7 +169,7 @@ module.exports = ({
|
|
|
165
169
|
const resourceType = req.resourceType()
|
|
166
170
|
if (!abortTypes.includes(resourceType)) {
|
|
167
171
|
debug('continue', { url: req.url(), resourceType })
|
|
168
|
-
return req.continue(req.continueRequestOverrides(),
|
|
172
|
+
return req.continue(req.continueRequestOverrides(), 0)
|
|
169
173
|
}
|
|
170
174
|
debug('abort', { url: req.url(), resourceType })
|
|
171
175
|
return req.abort('blockedbyclient', 2)
|
|
@@ -241,16 +245,6 @@ module.exports = ({
|
|
|
241
245
|
)
|
|
242
246
|
}
|
|
243
247
|
|
|
244
|
-
if (mediaType) {
|
|
245
|
-
prePromises.push(
|
|
246
|
-
run({
|
|
247
|
-
fn: page.emulateMediaType(mediaType),
|
|
248
|
-
timeout: actionTimeout,
|
|
249
|
-
debug: { mediaType }
|
|
250
|
-
})
|
|
251
|
-
)
|
|
252
|
-
}
|
|
253
|
-
|
|
254
248
|
if (timezone) {
|
|
255
249
|
prePromises.push(
|
|
256
250
|
run({
|
|
@@ -287,7 +281,7 @@ module.exports = ({
|
|
|
287
281
|
|
|
288
282
|
const { value } = await run({
|
|
289
283
|
fn: html ? page.setContent(html, args) : page.goto(url, args),
|
|
290
|
-
timeout,
|
|
284
|
+
timeout: gotoTimeout,
|
|
291
285
|
debug: html ? 'html' : 'url'
|
|
292
286
|
})
|
|
293
287
|
|
|
@@ -298,12 +292,22 @@ module.exports = ({
|
|
|
298
292
|
waitForTimeout
|
|
299
293
|
})) {
|
|
300
294
|
if (value) {
|
|
301
|
-
await run({ fn: page[key](value), timeout:
|
|
295
|
+
await run({ fn: page[key](value), timeout: gotoTimeout, debug: { [key]: value } })
|
|
302
296
|
}
|
|
303
297
|
}
|
|
304
298
|
|
|
305
299
|
const postPromises = []
|
|
306
300
|
|
|
301
|
+
if (mediaType) {
|
|
302
|
+
postPromises.push(
|
|
303
|
+
run({
|
|
304
|
+
fn: page.emulateMediaType(mediaType),
|
|
305
|
+
timeout: actionTimeout,
|
|
306
|
+
debug: { mediaType }
|
|
307
|
+
})
|
|
308
|
+
)
|
|
309
|
+
}
|
|
310
|
+
|
|
307
311
|
if (animations === false) {
|
|
308
312
|
postPromises.push(
|
|
309
313
|
run({
|
|
@@ -370,7 +374,11 @@ module.exports = ({
|
|
|
370
374
|
|
|
371
375
|
if (click) {
|
|
372
376
|
for (const selector of castArray(click)) {
|
|
373
|
-
await run({
|
|
377
|
+
await run({
|
|
378
|
+
fn: page.click(selector),
|
|
379
|
+
timeout: actionTimeout,
|
|
380
|
+
debug: { click: selector }
|
|
381
|
+
})
|
|
374
382
|
}
|
|
375
383
|
}
|
|
376
384
|
|
|
@@ -395,8 +403,7 @@ module.exports = ({
|
|
|
395
403
|
goto.deviceDescriptors = getDevice.deviceDescriptors
|
|
396
404
|
goto.defaultViewport = defaultViewport
|
|
397
405
|
goto.waitUntilAuto = _waitUntilAuto
|
|
398
|
-
goto.
|
|
399
|
-
goto.actionTimeout = actionTimeout
|
|
406
|
+
goto.timeouts = timeouts
|
|
400
407
|
goto.run = run
|
|
401
408
|
|
|
402
409
|
return goto
|