Make helper.getExceptionMessage synchronous
We now have description of an exception, no need for a roundtrip to the backend.
This commit is contained in:
parent
0960dc38d1
commit
aba61de905
@ -165,10 +165,8 @@ class FrameManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
expression = `Promise.resolve(${expression})`;
|
expression = `Promise.resolve(${expression})`;
|
||||||
let { exceptionDetails, result: remoteObject } = await this._client.send('Runtime.evaluate', { expression, contextId, returnByValue: false, awaitPromise: true });
|
let { exceptionDetails, result: remoteObject } = await this._client.send('Runtime.evaluate', { expression, contextId, returnByValue: false, awaitPromise: true });
|
||||||
if (exceptionDetails) {
|
if (exceptionDetails)
|
||||||
let message = await helper.getExceptionMessage(this._client, exceptionDetails);
|
throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails));
|
||||||
throw new Error('Evaluation failed: ' + message);
|
|
||||||
}
|
|
||||||
return await helper.serializeRemoteObject(this._client, remoteObject);
|
return await helper.serializeRemoteObject(this._client, remoteObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,10 +188,8 @@ class FrameManager extends EventEmitter {
|
|||||||
awaitPromise: true,
|
awaitPromise: true,
|
||||||
returnByValue: false,
|
returnByValue: false,
|
||||||
});
|
});
|
||||||
if (exceptionDetails) {
|
if (exceptionDetails)
|
||||||
let message = await helper.getExceptionMessage(this._client, exceptionDetails);
|
throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails));
|
||||||
throw new Error('Evaluation failed: ' + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} selector
|
* @param {string} selector
|
||||||
|
@ -207,8 +207,8 @@ class Page extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* @param {!Object} exceptionDetails
|
* @param {!Object} exceptionDetails
|
||||||
*/
|
*/
|
||||||
async _handleException(exceptionDetails) {
|
_handleException(exceptionDetails) {
|
||||||
let message = await helper.getExceptionMessage(this._client, exceptionDetails);
|
let message = helper.getExceptionMessage(exceptionDetails);
|
||||||
this.emit(Page.Events.PageError, new Error(message));
|
this.emit(Page.Events.PageError, new Error(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,24 +25,13 @@ class Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Connection} client
|
|
||||||
* @param {!Object} exceptionDetails
|
* @param {!Object} exceptionDetails
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
static async getExceptionMessage(client, exceptionDetails) {
|
static getExceptionMessage(exceptionDetails) {
|
||||||
let message = '';
|
if (exceptionDetails.exception)
|
||||||
let exception = exceptionDetails.exception;
|
return exceptionDetails.exception.description;
|
||||||
if (exception) {
|
let message = exceptionDetails.text;
|
||||||
let response = await client.send('Runtime.callFunctionOn', {
|
|
||||||
objectId: exception.objectId,
|
|
||||||
functionDeclaration: 'function() { return this.message; }',
|
|
||||||
returnByValue: true,
|
|
||||||
});
|
|
||||||
message = response.result.value;
|
|
||||||
} else {
|
|
||||||
message = exceptionDetails.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exceptionDetails.stackTrace) {
|
if (exceptionDetails.stackTrace) {
|
||||||
for (let callframe of exceptionDetails.stackTrace.callFrames) {
|
for (let callframe of exceptionDetails.stackTrace.callFrames) {
|
||||||
let location = callframe.url + ':' + callframe.lineNumber + ':' + callframe.columnNumber;
|
let location = callframe.url + ':' + callframe.lineNumber + ':' + callframe.columnNumber;
|
||||||
|
@ -240,7 +240,7 @@ describe('Puppeteer', function() {
|
|||||||
await page.waitFor('*');
|
await page.waitFor('*');
|
||||||
fail('Failed waitFor did not throw.');
|
fail('Failed waitFor did not throw.');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e.message).toContain('Evaluation failed: document.querySelector is not a function');
|
expect(e.message).toContain('document.querySelector is not a function');
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
it('should throw when frame is detached', SX(async function() {
|
it('should throw when frame is detached', SX(async function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user