Skip to content

Commit de606b9

Browse files
authored
fix(chromium): handle various exception values in pageerror (#2293)
1 parent 7efc22c commit de606b9

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/chromium/crProtocolHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import * as util from 'util';
2323

2424
export function getExceptionMessage(exceptionDetails: Protocol.Runtime.ExceptionDetails): string {
2525
if (exceptionDetails.exception)
26-
return exceptionDetails.exception.description || exceptionDetails.exception.value;
26+
return exceptionDetails.exception.description || String(exceptionDetails.exception.value);
2727
let message = exceptionDetails.text;
2828
if (exceptionDetails.stackTrace) {
2929
for (const callframe of exceptionDetails.stackTrace.callFrames) {

test/page.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,37 @@ describe('Page.Events.PageError', function() {
560560
]);
561561
expect(error.stack).toContain('myscript.js');
562562
});
563+
it('should handle odd values', async ({page}) => {
564+
const cases = [
565+
[null, 'null'],
566+
[undefined, 'undefined'],
567+
[0, '0'],
568+
['', ''],
569+
];
570+
for (const [value, message] of cases) {
571+
const [error] = await Promise.all([
572+
page.waitForEvent('pageerror'),
573+
page.evaluate(value => setTimeout(() => { throw value; }, 0), value),
574+
]);
575+
expect(error.message).toBe(FFOX ? 'uncaught exception: ' + message : message);
576+
}
577+
});
578+
it.fail(FFOX)('should handle object', async ({page}) => {
579+
// Firefox just does not report this error.
580+
const [error] = await Promise.all([
581+
page.waitForEvent('pageerror'),
582+
page.evaluate(() => setTimeout(() => { throw {}; }, 0)),
583+
]);
584+
expect(error.message).toBe(CHROMIUM ? 'Object' : '[object Object]');
585+
});
586+
it.fail(FFOX)('should handle window', async ({page}) => {
587+
// Firefox just does not report this error.
588+
const [error] = await Promise.all([
589+
page.waitForEvent('pageerror'),
590+
page.evaluate(() => setTimeout(() => { throw window; }, 0)),
591+
]);
592+
expect(error.message).toBe(CHROMIUM ? 'Window' : '[object Window]');
593+
});
563594
});
564595

565596
describe('Page.setContent', function() {

0 commit comments

Comments
 (0)