Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Dmitry Gozmande606b955367
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() {