Skip to content

Commit b8af1f1

Browse files
committed
fix: close the page before throwing
1 parent b103359 commit b8af1f1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function analyze (originalUrl) {
2323
try {
2424
url = new URL(originalUrl)
2525
} catch (e) {
26-
const error = new Error(`Invalid URL ${originalUrl}`)
26+
const error = new Error(`Invalid URL ${originalUrl}`)
2727
error.code = ERROR_CODES.INVALID_URL
2828
throw error
2929
}
@@ -82,6 +82,7 @@ async function analyze (originalUrl) {
8282
error.code = ERROR_CODES.HTTP_ERROR
8383
error.statusCode = response.status()
8484
error.body = await response.text()
85+
await page.close()
8586
throw error
8687
}
8788
// Get headers
@@ -90,6 +91,7 @@ async function analyze (originalUrl) {
9091
if (!(await isCrawlable(headers))) {
9192
const error = new Error(`Crawling is not allowed on ${originalUrl}`)
9293
error.code = ERROR_CODES.NOT_CRAWLABLE
94+
await page.close()
9395
throw error
9496
}
9597

@@ -109,6 +111,7 @@ async function analyze (originalUrl) {
109111
if (!(await hasVue(context))) {
110112
const error = new Error(`Vue is not detected on ${originalUrl}`)
111113
error.code = ERROR_CODES.VUE_NOT_DETECTED
114+
await page.close()
112115
throw error
113116
}
114117

@@ -148,7 +151,7 @@ async function analyze (originalUrl) {
148151

149152
// Get Nuxt modules if using NuxtJS
150153
if (infos.framework && infos.framework.name === 'NuxtJS') {
151-
const [ meta, modules ] = await Promise.all([
154+
const [meta, modules] = await Promise.all([
152155
getNuxtMeta(context),
153156
getNuxtModules(context)
154157
])
@@ -169,7 +172,6 @@ async function analyze (originalUrl) {
169172
})
170173

171174
await page.close()
172-
173175
return infos
174176
}
175177

0 commit comments

Comments
 (0)