@browserless/goto 9.3.0 → 9.3.4

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 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.4",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -29,22 +29,22 @@
29
29
  "puppeteer"
30
30
  ],
31
31
  "dependencies": {
32
- "@browserless/devices": "^9.3.0",
33
- "@cliqz/adblocker-puppeteer": "~1.23.0",
32
+ "@browserless/devices": "^9.3.3",
33
+ "@cliqz/adblocker-puppeteer": "~1.23.3",
34
34
  "debug-logfmt": "~1.0.4",
35
35
  "got": "~11.8.3",
36
- "is-url-http": "~2.2.5",
36
+ "is-url-http": "~2.2.7",
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.39",
42
+ "top-user-agents": "~1.0.40",
43
43
  "tough-cookie": "~4.0.0",
44
44
  "unique-random-array": "~2.0.0"
45
45
  },
46
46
  "devDependencies": {
47
- "ava": "latest",
47
+ "ava": "3",
48
48
  "browserless": "latest",
49
49
  "puppeteer": "latest",
50
50
  "signal-exit": "latest"
@@ -68,5 +68,5 @@
68
68
  "timeout": "2m",
69
69
  "verbose": true
70
70
  },
71
- "gitHead": "489d6fffc2e001fba2961838b73d10f916862676"
71
+ "gitHead": "7daa01ff1b4f10dd6694df10803e1ca0246668bf"
72
72
  }
package/src/engine.bin CHANGED
Binary file
package/src/index.js CHANGED
@@ -31,7 +31,7 @@ const castArray = value => [].concat(value).filter(Boolean)
31
31
 
32
32
  const run = async ({ fn, timeout, debug: props }) => {
33
33
  const debugProps = { duration: timeSpan() }
34
- const result = await pReflect(pTimeout(fn, timeout))
34
+ const result = await pReflect(timeout ? pTimeout(fn, timeout) : fn)
35
35
  debugProps.duration = prettyMs(debugProps.duration())
36
36
  if (result.isRejected) debugProps.error = result.reason.message || result.reason
37
37
  debug(props, debugProps)
@@ -91,6 +91,87 @@ const disableAnimations = `
91
91
  }
92
92
  `.trim()
93
93
 
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)
173
+ }
174
+
94
175
  module.exports = ({
95
176
  evasions = ALL_EVASIONS_KEYS,
96
177
  defaultDevice = 'Macbook Pro 13',
@@ -281,7 +362,7 @@ module.exports = ({
281
362
 
282
363
  await Promise.all(prePromises.concat(applyEvasions))
283
364
 
284
- const { value } = await run({
365
+ const { value: response } = await run({
285
366
  fn: html ? page.setContent(html, args) : page.goto(url, args),
286
367
  timeout: gotoTimeout,
287
368
  debug: html ? 'html' : 'url'
@@ -298,81 +379,16 @@ module.exports = ({
298
379
  }
299
380
  }
300
381
 
301
- const postPromises = []
302
-
303
- if (mediaType) {
304
- postPromises.push(
305
- run({
306
- fn: page.emulateMediaType(mediaType),
307
- timeout: actionTimeout,
308
- debug: { mediaType }
309
- })
310
- )
311
- }
312
-
313
- if (animations === false) {
314
- postPromises.push(
315
- run({
316
- fn: injectStyle(page, disableAnimations),
317
- timeout: actionTimeout,
318
- debug: 'disableAnimations'
319
- })
320
- )
321
- }
322
-
323
- if (hide) {
324
- postPromises.push(
325
- run({
326
- fn: injectStyle(page, `${castArray(hide).join(', ')} { visibility: hidden !important; }`),
327
- timeout: actionTimeout,
328
- debug: 'hide'
329
- })
330
- )
331
- }
332
-
333
- if (remove) {
334
- postPromises.push(
335
- run({
336
- fn: injectStyle(page, `${castArray(remove).join(', ')} { display: none !important; }`),
337
- timeout: actionTimeout,
338
- debug: 'remove'
339
- })
340
- )
341
- }
342
-
343
- if (modules) {
344
- postPromises.push(
345
- run({
346
- fn: Promise.all(
347
- castArray(modules).map(value => injectScript(page, value, { type: 'modules' }))
348
- ),
349
- timeout: actionTimeout,
350
- debug: 'modules'
351
- })
352
- )
353
- }
354
-
355
- if (scripts) {
356
- postPromises.push(
357
- run({
358
- fn: Promise.all(castArray(scripts).map(value => injectScript(page, value))),
359
- timeout: actionTimeout,
360
- debug: 'scripts'
361
- })
362
- )
363
- }
364
-
365
- if (styles) {
366
- postPromises.push(
367
- run({
368
- fn: Promise.all(castArray(styles).map(style => injectStyle(page, style))),
369
- timeout: actionTimeout,
370
- debug: 'styles'
371
- })
372
- )
373
- }
374
-
375
- 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
+ })
376
392
 
377
393
  if (click) {
378
394
  for (const selector of castArray(click)) {
@@ -393,10 +409,10 @@ module.exports = ({
393
409
  }
394
410
 
395
411
  if (isWaitUntilAuto) {
396
- await waitUntilAuto(page, { response: value, timeout: actionTimeout * 2 })
412
+ await waitUntilAuto(page, { response, timeout: actionTimeout * 2 })
397
413
  }
398
414
 
399
- return { response: value, device }
415
+ return { response, device }
400
416
  }
401
417
 
402
418
  goto.getDevice = getDevice
@@ -412,6 +428,5 @@ module.exports = ({
412
428
  }
413
429
 
414
430
  module.exports.parseCookies = parseCookies
415
- module.exports.injectScript = injectScript
416
- module.exports.injectStyle = injectStyle
431
+ module.exports.inject = inject
417
432
  module.exports.evasions = ALL_EVASIONS_KEYS