browserless 9.11.1-3 → 9.11.1
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/LICENSE.md +0 -0
- package/package.json +6 -6
- package/src/index.js +34 -37
package/LICENSE.md
CHANGED
|
File without changes
|
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.1
|
|
5
|
+
"version": "9.11.1",
|
|
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",
|
|
@@ -54,13 +53,14 @@
|
|
|
54
53
|
"files": [
|
|
55
54
|
"src"
|
|
56
55
|
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"test": "ava"
|
|
58
|
+
},
|
|
57
59
|
"license": "MIT",
|
|
58
60
|
"ava": {
|
|
59
61
|
"serial": true,
|
|
60
62
|
"timeout": "30s",
|
|
61
63
|
"workerThreads": false
|
|
62
64
|
},
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
}
|
|
65
|
+
"gitHead": "27c817029945630ccaede934c8a7e9fa5c2800aa"
|
|
66
|
+
}
|
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,48 +107,46 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
const withPage = (fn, { timeout: evaluateTimeout } = {}) =>
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
await close()
|
|
127
|
-
if (!isRejected) throw ensureError(error)
|
|
128
|
-
}
|
|
110
|
+
const withPage = (fn, { timeout: evaluateTimeout } = {}) => async (...args) => {
|
|
111
|
+
let isRejected = false
|
|
112
|
+
|
|
113
|
+
async function run () {
|
|
114
|
+
let page
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
page = await createPage(args)
|
|
118
|
+
setTimeout(() => closePage(page), timeout).unref()
|
|
119
|
+
const value = await fn(page)(...args)
|
|
120
|
+
await closePage(page)
|
|
121
|
+
return value
|
|
122
|
+
} catch (error) {
|
|
123
|
+
await closePage(page)
|
|
124
|
+
if (!isRejected) throw ensureError(error)
|
|
129
125
|
}
|
|
126
|
+
}
|
|
130
127
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
const { message, attemptNumber, retriesLeft } = error
|
|
142
|
-
debug('retry', { attemptNumber, retriesLeft, message })
|
|
128
|
+
const task = () =>
|
|
129
|
+
pRetry(run, {
|
|
130
|
+
retries: retry,
|
|
131
|
+
onFailedAttempt: async error => {
|
|
132
|
+
debug('onFailedAttempt', { name: error.name, code: error.code, isRejected })
|
|
133
|
+
if (error.name === 'AbortError') throw error
|
|
134
|
+
if (isRejected) throw new AbortError()
|
|
135
|
+
if (error.code === 'EBRWSRCONTEXTCONNRESET') {
|
|
136
|
+
_contextPromise = createBrowserContext(contextOpts)
|
|
143
137
|
}
|
|
144
|
-
|
|
138
|
+
const { message, attemptNumber, retriesLeft } = error
|
|
139
|
+
debug('retry', { attemptNumber, retriesLeft, message })
|
|
140
|
+
}
|
|
141
|
+
})
|
|
145
142
|
|
|
146
|
-
|
|
143
|
+
const timeout = evaluateTimeout || contextTimeout || globalTimeout
|
|
147
144
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
})
|
|
145
|
+
return pTimeout(task(), timeout, () => {
|
|
146
|
+
isRejected = true
|
|
147
|
+
throw browserTimeout({ timeout })
|
|
152
148
|
})
|
|
149
|
+
}
|
|
153
150
|
|
|
154
151
|
const evaluate = (fn, gotoOpts) =>
|
|
155
152
|
withPage(
|