browserless 9.11.1-4 → 9.11.2-beta.0
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 +1 -2
- package/src/index.js +38 -37
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "browserless",
|
|
3
3
|
"description": "The headless Chrome/Chromium performance driver for Node.js",
|
|
4
4
|
"homepage": "https://browserless.js.org",
|
|
5
|
-
"version": "9.11.
|
|
5
|
+
"version": "9.11.2-beta.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"@browserless/screenshot": "^9.11.0",
|
|
38
38
|
"debug-logfmt": "~1.0.4",
|
|
39
39
|
"kill-process-group": "~1.0.3",
|
|
40
|
-
"p-cancelable": "2.1.1",
|
|
41
40
|
"p-reflect": "~2.1.0",
|
|
42
41
|
"p-retry": "~4.6.1",
|
|
43
42
|
"p-timeout": "~4.1.0",
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,6 @@ const createScreenshot = require('@browserless/screenshot')
|
|
|
5
5
|
const debug = require('debug-logfmt')('browserless')
|
|
6
6
|
const createGoto = require('@browserless/goto')
|
|
7
7
|
const createPdf = require('@browserless/pdf')
|
|
8
|
-
const PCancelable = require('p-cancelable')
|
|
9
8
|
const { withLock } = require('superlock')
|
|
10
9
|
const pReflect = require('p-reflect')
|
|
11
10
|
const pTimeout = require('p-timeout')
|
|
@@ -108,47 +107,49 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
const withPage =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
110
|
+
const withPage =
|
|
111
|
+
(fn, { timeout: evaluateTimeout } = {}) =>
|
|
112
|
+
async (...args) => {
|
|
113
|
+
let isRejected = false
|
|
114
|
+
|
|
115
|
+
async function run () {
|
|
116
|
+
let page
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
page = await createPage(args)
|
|
120
|
+
setTimeout(() => closePage(page), timeout).unref()
|
|
121
|
+
|
|
122
|
+
const value = await fn(page, goto)(...args)
|
|
123
|
+
await closePage(page)
|
|
124
|
+
return value
|
|
125
|
+
} catch (error) {
|
|
126
|
+
await closePage(page)
|
|
127
|
+
if (!isRejected) throw ensureError(error)
|
|
128
|
+
}
|
|
127
129
|
}
|
|
128
|
-
}
|
|
129
130
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
const task = () =>
|
|
132
|
+
pRetry(run, {
|
|
133
|
+
retries: retry,
|
|
134
|
+
onFailedAttempt: async error => {
|
|
135
|
+
debug('onFailedAttempt', { name: error.name, code: error.code, isRejected })
|
|
136
|
+
if (error.name === 'AbortError') throw error
|
|
137
|
+
if (isRejected) throw new AbortError()
|
|
138
|
+
if (error.code === 'EBRWSRCONTEXTCONNRESET') {
|
|
139
|
+
_contextPromise = createBrowserContext(contextOpts)
|
|
140
|
+
}
|
|
141
|
+
const { message, attemptNumber, retriesLeft } = error
|
|
142
|
+
debug('retry', { attemptNumber, retriesLeft, message })
|
|
139
143
|
}
|
|
140
|
-
|
|
141
|
-
debug('retry', { attemptNumber, retriesLeft, message })
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
+
})
|
|
144
145
|
|
|
145
|
-
|
|
146
|
+
const timeout = evaluateTimeout || contextTimeout || globalTimeout
|
|
146
147
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
148
|
+
return pTimeout(task(), timeout, () => {
|
|
149
|
+
isRejected = true
|
|
150
|
+
throw browserTimeout({ timeout })
|
|
151
|
+
})
|
|
152
|
+
}
|
|
152
153
|
|
|
153
154
|
const evaluate = (fn, gotoOpts) =>
|
|
154
155
|
withPage(
|