Skip to content

Commit

Permalink
handle uncaught exceptions from launching puppeteer browser
Browse files Browse the repository at this point in the history
  • Loading branch information
pocketjoso committed Jan 6, 2019
1 parent 7f5f006 commit de57e06
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,21 @@ const generateCriticalCssWrapped = async function generateCriticalCssWrapped (
'\ncss length: ' +
options.cssString.length
)
await restartBrowser({
width,
height,
getBrowser: options.puppeteer && options.puppeteer.getBrowser
})
// retry
resolve(
generateCriticalCssWrapped(options, {
forceTryRestartBrowser: true
try {
await restartBrowser({
width,
height,
getBrowser: options.puppeteer && options.puppeteer.getBrowser
})
)
// retry
resolve(
generateCriticalCssWrapped(options, {
forceTryRestartBrowser: true
})
)
} catch (e) {
reject(e)
}
return
}
reject(e)
Expand Down Expand Up @@ -222,13 +226,13 @@ module.exports = function (options, callback) {

const width = parseInt(options.width || DEFAULT_VIEWPORT_WIDTH, 10)
const height = parseInt(options.height || DEFAULT_VIEWPORT_HEIGHT, 10)
// launch the browser
await launchBrowserIfNeeded({
getBrowser: options.puppeteer && options.puppeteer.getBrowser,
width,
height
})
try {
// launch the browser
await launchBrowserIfNeeded({
getBrowser: options.puppeteer && options.puppeteer.getBrowser,
width,
height
})
const criticalCss = await generateCriticalCssWrapped(options)
cleanupAndExit({ returnValue: criticalCss })
} catch (err) {
Expand Down

0 comments on commit de57e06

Please sign in to comment.