|
|
|
@ -1,8 +1,5 @@ |
|
|
|
async function listenForErrors(browser, page) { |
|
|
|
async function listenForErrors(browser, page) { |
|
|
|
const ignoredErrors = [ |
|
|
|
const ignoredErrors = ['ERR_ABORTED', 'MEDIA_ERR_SRC_NOT_SUPPORTED', '404']; |
|
|
|
'ERR_ABORTED', |
|
|
|
|
|
|
|
'MEDIA_ERR_SRC_NOT_SUPPORTED', |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Emitted when the page emits an error event (for example, the page crashes)
|
|
|
|
// Emitted when the page emits an error event (for example, the page crashes)
|
|
|
|
page.on('error', (error) => { |
|
|
|
page.on('error', (error) => { |
|
|
|
@ -20,7 +17,9 @@ async function listenForErrors(browser, page) { |
|
|
|
|
|
|
|
|
|
|
|
// Catch all failed requests like 4xx..5xx status codes
|
|
|
|
// Catch all failed requests like 4xx..5xx status codes
|
|
|
|
page.on('requestfailed', (request) => { |
|
|
|
page.on('requestfailed', (request) => { |
|
|
|
const ignoreError = ignoredErrors.some(e => request.failure().errorText.includes(e)); |
|
|
|
const ignoreError = ignoredErrors.some((e) => |
|
|
|
|
|
|
|
request.failure().errorText.includes(e) |
|
|
|
|
|
|
|
); |
|
|
|
if (!ignoreError) { |
|
|
|
if (!ignoreError) { |
|
|
|
throw new Error( |
|
|
|
throw new Error( |
|
|
|
`❌ url: ${request.url()}, errText: ${ |
|
|
|
`❌ url: ${request.url()}, errText: ${ |
|
|
|
@ -31,18 +30,17 @@ async function listenForErrors(browser, page) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Listen for console errors in the browser.
|
|
|
|
// Listen for console errors in the browser.
|
|
|
|
page.on('console', msg => { |
|
|
|
page.on('console', (msg) => { |
|
|
|
const type = msg._type; |
|
|
|
const type = msg._type; |
|
|
|
if (type !== 'error') { |
|
|
|
if (type !== 'error') { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const ignoreError = ignoredErrors.some(e => msg._text.includes(e)); |
|
|
|
const ignoreError = ignoredErrors.some((e) => msg._text.includes(e)); |
|
|
|
if (!ignoreError) { |
|
|
|
if (!ignoreError) { |
|
|
|
throw new Error(`❌ ${msg._text}`); |
|
|
|
throw new Error(`❌ ${msg._text}`); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports.listenForErrors = listenForErrors; |
|
|
|
module.exports.listenForErrors = listenForErrors; |
|
|
|
|