browserless 9.10.2 → 9.11.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 +7 -6
- package/src/index.js +40 -35
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.
|
|
5
|
+
"version": "9.11.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -32,11 +32,12 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@browserless/errors": "^9.10.2",
|
|
35
|
-
"@browserless/goto": "^9.
|
|
36
|
-
"@browserless/pdf": "^9.
|
|
37
|
-
"@browserless/screenshot": "^9.
|
|
35
|
+
"@browserless/goto": "^9.11.0",
|
|
36
|
+
"@browserless/pdf": "^9.11.0",
|
|
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",
|
|
40
41
|
"p-reflect": "~2.1.0",
|
|
41
42
|
"p-retry": "~4.6.1",
|
|
42
43
|
"p-timeout": "~4.1.0",
|
|
@@ -44,7 +45,7 @@
|
|
|
44
45
|
"superlock": "~1.0.1"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@browserless/test": "^9.
|
|
48
|
+
"@browserless/test": "^9.11.0",
|
|
48
49
|
"ava": "latest"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
"timeout": "30s",
|
|
60
61
|
"workerThreads": false
|
|
61
62
|
},
|
|
62
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "9e24768346df1dda9df4be065137deb1783c37c3",
|
|
63
64
|
"scripts": {
|
|
64
65
|
"test": "ava"
|
|
65
66
|
}
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ 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')
|
|
8
9
|
const { withLock } = require('superlock')
|
|
9
10
|
const pReflect = require('p-reflect')
|
|
10
11
|
const pTimeout = require('p-timeout')
|
|
@@ -107,46 +108,50 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
const withPage = (fn, { timeout: evaluateTimeout } = {}) =>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
111
|
+
const withPage = (fn, { timeout: evaluateTimeout } = {}) =>
|
|
112
|
+
PCancelable.fn(async (...args) => {
|
|
113
|
+
const onCancel = args.pop()
|
|
114
|
+
let isRejected = false
|
|
115
|
+
|
|
116
|
+
async function run () {
|
|
117
|
+
let page
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
page = await createPage(args)
|
|
121
|
+
const close = () => closePage(page)
|
|
122
|
+
onCancel(close)
|
|
123
|
+
setTimeout(close, timeout).unref()
|
|
124
|
+
const value = await fn(page)(...args)
|
|
125
|
+
await closePage(page)
|
|
126
|
+
return value
|
|
127
|
+
} catch (error) {
|
|
128
|
+
await closePage(page)
|
|
129
|
+
if (!isRejected) throw ensureError(error)
|
|
130
|
+
}
|
|
125
131
|
}
|
|
126
|
-
}
|
|
127
132
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
const task = () =>
|
|
134
|
+
pRetry(run, {
|
|
135
|
+
retries: retry,
|
|
136
|
+
onFailedAttempt: async error => {
|
|
137
|
+
debug('onFailedAttempt', { name: error.name, code: error.code, isRejected })
|
|
138
|
+
if (error.name === 'AbortError') throw error
|
|
139
|
+
if (isRejected) throw new AbortError()
|
|
140
|
+
if (error.code === 'EBRWSRCONTEXTCONNRESET') {
|
|
141
|
+
_contextPromise = createBrowserContext(contextOpts)
|
|
142
|
+
}
|
|
143
|
+
const { message, attemptNumber, retriesLeft } = error
|
|
144
|
+
debug('retry', { attemptNumber, retriesLeft, message })
|
|
137
145
|
}
|
|
138
|
-
|
|
139
|
-
debug('retry', { attemptNumber, retriesLeft, message })
|
|
140
|
-
}
|
|
141
|
-
})
|
|
146
|
+
})
|
|
142
147
|
|
|
143
|
-
|
|
148
|
+
const timeout = evaluateTimeout || contextTimeout || globalTimeout
|
|
144
149
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
150
|
+
return pTimeout(task(), timeout, () => {
|
|
151
|
+
isRejected = true
|
|
152
|
+
throw browserTimeout({ timeout })
|
|
153
|
+
})
|
|
148
154
|
})
|
|
149
|
-
}
|
|
150
155
|
|
|
151
156
|
const evaluate = (fn, gotoOpts) =>
|
|
152
157
|
withPage(
|
|
@@ -172,7 +177,7 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
172
177
|
browser: getBrowser,
|
|
173
178
|
evaluate,
|
|
174
179
|
goto,
|
|
175
|
-
html: evaluate(page => page.content()
|
|
180
|
+
html: evaluate(page => page.content()),
|
|
176
181
|
page: createPage,
|
|
177
182
|
pdf: withPage(createPdf({ goto })),
|
|
178
183
|
screenshot: withPage(createScreenshot({ goto })),
|