browserless 10.7.6 → 10.7.8
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 +3 -3
- package/src/index.js +58 -45
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": "10.7.
|
|
5
|
+
"version": "10.7.8",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@browserless/errors": "^10.7.1",
|
|
35
35
|
"@browserless/goto": "^10.7.6",
|
|
36
36
|
"@browserless/pdf": "^10.7.6",
|
|
37
|
-
"@browserless/screenshot": "^10.7.
|
|
37
|
+
"@browserless/screenshot": "^10.7.7",
|
|
38
38
|
"debug-logfmt": "~1.2.3",
|
|
39
39
|
"kill-process-group": "~1.0.11",
|
|
40
40
|
"p-reflect": "~2.1.0",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"timeout": "2m",
|
|
65
65
|
"workerThreads": false
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "d253216077d72daa09942484dba75f3cfe365a08"
|
|
68
68
|
}
|
package/src/index.js
CHANGED
|
@@ -78,13 +78,15 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
78
78
|
|
|
79
79
|
const getBrowserContext = () => _contextPromise
|
|
80
80
|
|
|
81
|
-
const createPage = async
|
|
81
|
+
const createPage = async name => {
|
|
82
|
+
const duration = debug.duration('createPage')
|
|
82
83
|
const [browserProcess, browserContext] = await Promise.all([
|
|
83
84
|
getBrowser(),
|
|
84
85
|
getBrowserContext()
|
|
85
86
|
])
|
|
86
87
|
const page = await browserContext.newPage()
|
|
87
|
-
|
|
88
|
+
duration({
|
|
89
|
+
name,
|
|
88
90
|
id: page._client().id(),
|
|
89
91
|
contextId: browserContext.id,
|
|
90
92
|
browserPid: driver.pid(browserProcess)
|
|
@@ -92,14 +94,16 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
92
94
|
return page
|
|
93
95
|
}
|
|
94
96
|
|
|
95
|
-
const closePage = async page => {
|
|
97
|
+
const closePage = async (page, name) => {
|
|
96
98
|
if (page && !page.isClosed()) {
|
|
99
|
+
const duration = debug.duration('closePage')
|
|
97
100
|
const [browserProcess, browserContext] = await Promise.all([
|
|
98
101
|
getBrowser(),
|
|
99
102
|
getBrowserContext(),
|
|
100
103
|
pReflect(page.close())
|
|
101
104
|
])
|
|
102
|
-
|
|
105
|
+
duration({
|
|
106
|
+
name,
|
|
103
107
|
id: page._client().id(),
|
|
104
108
|
contextId: browserContext.id,
|
|
105
109
|
browserPid: driver.pid(browserProcess)
|
|
@@ -107,55 +111,64 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
const withPage =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
114
|
+
const withPage = (fn, { timeout: evaluateTimeout } = {}) => {
|
|
115
|
+
const name = fn.name || 'anonymous'
|
|
116
|
+
|
|
117
|
+
return async (...args) => {
|
|
118
|
+
let isRejected = false
|
|
119
|
+
|
|
120
|
+
async function run () {
|
|
121
|
+
let page
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
page = await createPage(name)
|
|
125
|
+
setTimeout(() => closePage(page, name), timeout).unref()
|
|
126
|
+
const value = await fn(page, goto)(...args)
|
|
127
|
+
await closePage(page, `${name}:success`)
|
|
128
|
+
return value
|
|
129
|
+
} catch (error) {
|
|
130
|
+
await closePage(page, `${name}:error`)
|
|
131
|
+
if (!isRejected) throw ensureError(error)
|
|
128
132
|
}
|
|
133
|
+
}
|
|
129
134
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
const { message, attemptNumber, retriesLeft } = error
|
|
141
|
-
debug('retry', { attemptNumber, retriesLeft, message })
|
|
135
|
+
const task = () =>
|
|
136
|
+
pRetry(run, {
|
|
137
|
+
retries: retry,
|
|
138
|
+
onFailedAttempt: async error => {
|
|
139
|
+
debug('onFailedAttempt', { name: error.name, code: error.code, isRejected })
|
|
140
|
+
if (error.name === 'AbortError') throw error
|
|
141
|
+
if (isRejected || isDestroyedForced) throw new AbortError()
|
|
142
|
+
if (error.code === 'EBRWSRCONTEXTCONNRESET') {
|
|
143
|
+
_contextPromise = createBrowserContext(contextOpts)
|
|
142
144
|
}
|
|
143
|
-
|
|
145
|
+
const { message, attemptNumber, retriesLeft } = error
|
|
146
|
+
debug('retry', { attemptNumber, retriesLeft, message })
|
|
147
|
+
}
|
|
148
|
+
})
|
|
144
149
|
|
|
145
|
-
|
|
150
|
+
const timeout = evaluateTimeout || contextTimeout || globalTimeout
|
|
146
151
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
return pTimeout(task(), timeout, () => {
|
|
153
|
+
isRejected = true
|
|
154
|
+
throw browserTimeout({ timeout })
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
}
|
|
152
158
|
|
|
153
159
|
const evaluate = (fn, gotoOpts) =>
|
|
154
160
|
withPage(
|
|
155
|
-
(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
Object.defineProperty(
|
|
162
|
+
(page, goto) => async (url, opts) => {
|
|
163
|
+
const { response, error } = await goto(page, { url, ...gotoOpts, ...opts })
|
|
164
|
+
return fn(page, response, error)
|
|
165
|
+
},
|
|
166
|
+
'name',
|
|
167
|
+
{
|
|
168
|
+
value: fn.name || 'evaluate',
|
|
169
|
+
writable: false
|
|
170
|
+
}
|
|
171
|
+
),
|
|
159
172
|
gotoOpts
|
|
160
173
|
)
|
|
161
174
|
|