browserless 10.10.1 → 10.10.3
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 +5 -5
- package/src/index.js +20 -24
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "browserless",
|
|
3
3
|
"description": "The headless Chrome/Chromium driver on top of Puppeteer. Take screenshots, generate PDFs, extract text and HTML with a production-ready API.",
|
|
4
4
|
"homepage": "https://browserless.js.org",
|
|
5
|
-
"version": "10.10.
|
|
5
|
+
"version": "10.10.3",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@browserless/errors": "^10.10.1",
|
|
38
|
-
"@browserless/goto": "^10.10.
|
|
39
|
-
"@browserless/pdf": "^10.10.
|
|
40
|
-
"@browserless/screenshot": "^10.10.
|
|
38
|
+
"@browserless/goto": "^10.10.2",
|
|
39
|
+
"@browserless/pdf": "^10.10.3",
|
|
40
|
+
"@browserless/screenshot": "^10.10.3",
|
|
41
41
|
"debug-logfmt": "~1.4.7",
|
|
42
42
|
"kill-process-group": "~1.0.13",
|
|
43
43
|
"p-reflect": "~2.1.0",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"timeout": "2m",
|
|
68
68
|
"workerThreads": false
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "4d2b893e8215a91d830f4471f51c567a53cd6bbb"
|
|
71
71
|
}
|
package/src/index.js
CHANGED
|
@@ -74,22 +74,22 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
74
74
|
const createContext = async ({ retry = 2, timeout: contextTimeout, ...contextOpts } = {}) => {
|
|
75
75
|
let _contextPromise = createBrowserContext(contextOpts)
|
|
76
76
|
let isDestroyedForced = false
|
|
77
|
+
const pageMetadata = new WeakMap()
|
|
77
78
|
|
|
78
79
|
const getBrowserContext = () => _contextPromise
|
|
79
80
|
|
|
80
81
|
const createPage = async name => {
|
|
81
82
|
const duration = debug.duration('createPage')
|
|
82
|
-
const
|
|
83
|
-
getBrowser(),
|
|
84
|
-
getBrowserContext()
|
|
85
|
-
])
|
|
83
|
+
const browserContext = await getBrowserContext()
|
|
86
84
|
const page = await browserContext.newPage()
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
const browser = typeof page.browser === 'function' ? page.browser() : undefined
|
|
86
|
+
const metadata = {
|
|
89
87
|
id: page._client().id(),
|
|
90
88
|
contextId: browserContext.id,
|
|
91
|
-
browserPid: driver.pid(
|
|
92
|
-
}
|
|
89
|
+
browserPid: browser ? driver.pid(browser) : undefined
|
|
90
|
+
}
|
|
91
|
+
pageMetadata.set(page, metadata)
|
|
92
|
+
duration({ name, ...metadata })
|
|
93
93
|
return page
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -97,17 +97,9 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
97
97
|
if (page && !page.isClosed()) {
|
|
98
98
|
const duration = debug.duration('closePage')
|
|
99
99
|
if (page.disableAdblock) page.disableAdblock()
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
pReflect(page.close())
|
|
104
|
-
])
|
|
105
|
-
duration({
|
|
106
|
-
name,
|
|
107
|
-
id: page._client().id(),
|
|
108
|
-
contextId: browserContext.id,
|
|
109
|
-
browserPid: driver.pid(browserProcess)
|
|
110
|
-
})
|
|
100
|
+
await pReflect(page.close())
|
|
101
|
+
duration({ name, ...(pageMetadata.get(page) || {}) })
|
|
102
|
+
pageMetadata.delete(page)
|
|
111
103
|
}
|
|
112
104
|
}
|
|
113
105
|
|
|
@@ -119,21 +111,25 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
119
111
|
|
|
120
112
|
async function run () {
|
|
121
113
|
let page
|
|
114
|
+
let closePageTimeout
|
|
122
115
|
|
|
123
116
|
try {
|
|
124
117
|
page = await createPage(name)
|
|
125
|
-
setTimeout(() => {
|
|
118
|
+
closePageTimeout = setTimeout(() => {
|
|
126
119
|
closePage(page, name).catch(error => {
|
|
127
120
|
const { message, code, name } = ensureError(error)
|
|
128
121
|
debug('closePage:timeout:error', { message, code, name })
|
|
129
122
|
})
|
|
130
|
-
}, timeout)
|
|
123
|
+
}, timeout)
|
|
124
|
+
if (typeof closePageTimeout.unref === 'function') closePageTimeout.unref()
|
|
131
125
|
const value = await fn(page, goto)(...args)
|
|
132
126
|
await closePage(page, `${name}:success`)
|
|
133
127
|
return value
|
|
134
128
|
} catch (error) {
|
|
135
129
|
await closePage(page, `${name}:error`)
|
|
136
130
|
if (!isRejected) throw ensureError(error)
|
|
131
|
+
} finally {
|
|
132
|
+
if (closePageTimeout) clearTimeout(closePageTimeout)
|
|
137
133
|
}
|
|
138
134
|
}
|
|
139
135
|
|
|
@@ -144,9 +140,9 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
144
140
|
debug('onFailedAttempt', { name: error.name, code: error.code, isRejected })
|
|
145
141
|
if (error.name === 'AbortError') throw error
|
|
146
142
|
if (isRejected || isDestroyedForced) throw new AbortError()
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
const isRetryable = error.code === 'EBRWSRCONTEXTCONNRESET'
|
|
144
|
+
if (!isRetryable) throw error
|
|
145
|
+
_contextPromise = createBrowserContext(contextOpts)
|
|
150
146
|
const { message, attemptNumber, retriesLeft } = error
|
|
151
147
|
debug('retry', { attemptNumber, retriesLeft, message })
|
|
152
148
|
}
|