fix(chromium): handle various exception values in pageerror (#2293)

This commit is contained in:
Dmitry Gozman 2020-05-19 15:20:49 -07:00 committed by GitHub
parent 7efc22c062
commit de606b9553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -23,7 +23,7 @@ import * as util from 'util';
export function getExceptionMessage(exceptionDetails: Protocol.Runtime.ExceptionDetails): string {
if (exceptionDetails.exception)
return exceptionDetails.exception.description || exceptionDetails.exception.value;
return exceptionDetails.exception.description || String(exceptionDetails.exception.value);
let message = exceptionDetails.text;
if (exceptionDetails.stackTrace) {
for (const callframe of exceptionDetails.stackTrace.callFrames) {

View File

@ -560,6 +560,37 @@ describe('Page.Events.PageError', function() {
]);
expect(error.stack).toContain('myscript.js');
});
it('should handle odd values', async ({page}) => {
const cases = [
[null, 'null'],
[undefined, 'undefined'],
[0, '0'],
['', ''],
];
for (const [value, message] of cases) {
const [error] = await Promise.all([
page.waitForEvent('pageerror'),
page.evaluate(value => setTimeout(() => { throw value; }, 0), value),
]);
expect(error.message).toBe(FFOX ? 'uncaught exception: ' + message : message);
}
});
it.fail(FFOX)('should handle object', async ({page}) => {
// Firefox just does not report this error.
const [error] = await Promise.all([
page.waitForEvent('pageerror'),
page.evaluate(() => setTimeout(() => { throw {}; }, 0)),
]);
expect(error.message).toBe(CHROMIUM ? 'Object' : '[object Object]');
});
it.fail(FFOX)('should handle window', async ({page}) => {
// Firefox just does not report this error.
const [error] = await Promise.all([
page.waitForEvent('pageerror'),
page.evaluate(() => setTimeout(() => { throw window; }, 0)),
]);
expect(error.message).toBe(CHROMIUM ? 'Window' : '[object Window]');
});
});
describe('Page.setContent', function() {