mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 06:02:57 +03:00
fix(chromium): handle various exception values in pageerror (#2293)
This commit is contained in:
parent
7efc22c062
commit
de606b9553
@ -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) {
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user