diff --git a/buildtools/check-example.js b/buildtools/check-example.js index 04ea43465cd0..13207b2e8b13 100644 --- a/buildtools/check-example.js +++ b/buildtools/check-example.js @@ -61,13 +61,9 @@ const OSMImage = fileMock('osm.png', 'image/png'); const ASITVDCapabilities = fileMock('asitvd.capabilities.xml', 'text/xml'); const SgxCapabilities = fileMock('sgx.capabilities.xml', 'text/xml'); let browser; -let browserClosed = false; process.on('unhandledRejection', async (reason, promise) => { console.log('UnhandledRejection: ', promise, 'reason:', reason); - if (browser && !browserClosed) { - await browser.close(); - } process.exit(2); }); @@ -88,7 +84,6 @@ function loaded(page, browser) { console.log(`The page take more than 60s. to load (${(new Date() - start) / 1000}).`); console.log('Pending requests:'); requestsURL.forEach((request) => console.log(request)); - await browser.close(); process.exit(2); } else { timeout = undefined; @@ -105,26 +100,25 @@ function loaded(page, browser) { .then( async () => { console.log(`Screenshot saved at: ${screenshotPath}`); - await browser.close(); }, async (e) => { console.log(`Screenshot error: ${e}`); - await browser.close(); process.exit(2); }, ); }, 1000); - } else { - await browser.close(); } } }, 500); } (async () => { browser = await puppeteer.launch({ - args: ['--no-sandbox', '--disable-web-security', '--single-process'], + args: ['--no-sandbox', '--disable-web-security', '--single-process', '--incognito'], headless: true, }); + process.on('exit', (code) => { + browser.close(); + }); const page = await browser.newPage(); await page.setViewport({width: 900, height: 1080}); @@ -132,13 +126,11 @@ function loaded(page, browser) { page.on('pageerror', async (e) => { console.log('Page error'); console.log(e); - await browser.close(); process.exit(2); }); page.on('dialog', async (e) => { console.log('Unexpected alert message'); console.log(e); - await browser.close(); process.exit(2); }); page.on('request', (request) => { @@ -259,7 +251,6 @@ function loaded(page, browser) { !url.startsWith('https://maps.googleapis.com/') ) { console.log(`Request failed on: ${url}`); - await browser.close(); process.exit(2); } loaded(page, browser); @@ -285,21 +276,16 @@ function loaded(page, browser) { .text() .includes('Multiple versions of Lit loaded. Loading multiple versions is not recommended.') ) { - await browser.close(); process.exit(2); } } }); await page.goto(page_url).catch(async (error) => { console.log(`Page load error: ${error}.`); - await browser.close(); process.exit(2); }); loaded(page, browser); })().catch(async (error) => { console.log(`Unexpected error: ${error}.`); - if (browser && !browserClosed) { - await browser.close(); - } process.exit(2); });