Skip to content

Commit 93ddb8a

Browse files
committed
clean up shutdown procedure
1 parent 2c3cf46 commit 93ddb8a

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

src/check.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const startChecking = async (browser) => {
5252
const page = await browser.newPage()
5353

5454
while (true) {
55-
console.log('ℹ You can exit by hitting CTRL+C ...but it may take a minute to fully exit.')
55+
console.log('ℹ You can exit by hitting CTRL+C ...but it may take ~10sec to fully exit.')
5656

5757
await checkAllSites(page)
5858

src/index.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,8 @@ import {
66
HIDE_BROWSER, BROWSER_SIZE,
77
} from '../privateConfig.js'
88

9-
let browser
10-
11-
// TODO: On Windows, there is a long pause between the browser closing and "Closing browser..."
12-
// getting logged. Somehow CTRL+C stops Puppeteer browser before this function runs.
13-
// And why is there such a long pause?
9+
// TODO: On Windows, there is a long pause between the browser closing and exiting the process.
1410
const shutDown = async (code = 0) => {
15-
if (browser) {
16-
logger.log('🏁 Closing browser...')
17-
await browser.close() // TODO: Node doesn't seem to wait for this.
18-
console.log('why doesn\'t this show up?')
19-
}
2011
process.exit(code)
2112
}
2213

@@ -33,14 +24,14 @@ process.on('exit', () => {
3324
const start = async () => {
3425
logger.log('🚦 Launching browser...')
3526
const { height, width } = BROWSER_SIZE
36-
browser = await puppeteer.launch({
27+
const browser = await puppeteer.launch({
3728
headless: HIDE_BROWSER,
3829
defaultViewport: { width, height },
3930
args: [`--window-size=${width},${height}`]
4031
})
4132

4233
try {
43-
startChecking(browser)
34+
await startChecking(browser)
4435
} catch (err) {
4536
logger.error('💥 App failure:', err)
4637
await shutDown(1)

0 commit comments

Comments
 (0)