Skip to content

Commit

Permalink
fix(chromium): handle various exception values in pageerror (#2293)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored May 19, 2020
1 parent 7efc22c commit de606b9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/chromium/crProtocolHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions test/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit de606b9

Please sign in to comment.