From de606b9553677e44cf18596d6eb83654d7352f62 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 19 May 2020 15:20:49 -0700 Subject: [PATCH] fix(chromium): handle various exception values in pageerror (#2293) --- src/chromium/crProtocolHelper.ts | 2 +- test/page.spec.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/chromium/crProtocolHelper.ts b/src/chromium/crProtocolHelper.ts index bbcf8eaec3..abc22b212d 100644 --- a/src/chromium/crProtocolHelper.ts +++ b/src/chromium/crProtocolHelper.ts @@ -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) { diff --git a/test/page.spec.js b/test/page.spec.js index d515408dd9..43d53f26c7 100644 --- a/test/page.spec.js +++ b/test/page.spec.js @@ -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() {