mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(Page): report 'Log' domain entries as 'console' events (#2400)
Fixes #1939
This commit is contained in:
parent
58c46680f3
commit
e236887bbb
13
lib/Page.js
13
lib/Page.js
@ -50,6 +50,7 @@ class Page extends EventEmitter {
|
|||||||
client.send('Runtime.enable', {}),
|
client.send('Runtime.enable', {}),
|
||||||
client.send('Security.enable', {}),
|
client.send('Security.enable', {}),
|
||||||
client.send('Performance.enable', {}),
|
client.send('Performance.enable', {}),
|
||||||
|
client.send('Log.enable', {}),
|
||||||
]);
|
]);
|
||||||
if (ignoreHTTPSErrors)
|
if (ignoreHTTPSErrors)
|
||||||
await client.send('Security.setOverrideCertificateErrors', {override: true});
|
await client.send('Security.setOverrideCertificateErrors', {override: true});
|
||||||
@ -103,7 +104,7 @@ class Page extends EventEmitter {
|
|||||||
client.on('Security.certificateError', event => this._onCertificateError(event));
|
client.on('Security.certificateError', event => this._onCertificateError(event));
|
||||||
client.on('Inspector.targetCrashed', event => this._onTargetCrashed());
|
client.on('Inspector.targetCrashed', event => this._onTargetCrashed());
|
||||||
client.on('Performance.metrics', event => this._emitMetrics(event));
|
client.on('Performance.metrics', event => this._emitMetrics(event));
|
||||||
|
client.on('Log.entryAdded', event => this._onLogEntryAdded(event));
|
||||||
this._target._isClosedPromise.then(() => this.emit(Page.Events.Close));
|
this._target._isClosedPromise.then(() => this.emit(Page.Events.Close));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +126,14 @@ class Page extends EventEmitter {
|
|||||||
this.emit('error', new Error('Page crashed!'));
|
this.emit('error', new Error('Page crashed!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onLogEntryAdded(event) {
|
||||||
|
const {level, text, args} = event.entry;
|
||||||
|
if (args)
|
||||||
|
args.map(arg => helper.releaseObject(this._client, arg));
|
||||||
|
|
||||||
|
this.emit(Page.Events.Console, new ConsoleMessage(level, text));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {!Puppeteer.Frame}
|
* @return {!Puppeteer.Frame}
|
||||||
*/
|
*/
|
||||||
@ -1048,7 +1057,7 @@ class ConsoleMessage {
|
|||||||
* @param {string} text
|
* @param {string} text
|
||||||
* @param {!Array<*>} args
|
* @param {!Array<*>} args
|
||||||
*/
|
*/
|
||||||
constructor(type, text, args) {
|
constructor(type, text, args = []) {
|
||||||
this._type = type;
|
this._type = type;
|
||||||
this._text = text;
|
this._text = text;
|
||||||
this._args = args;
|
this._args = args;
|
||||||
|
@ -331,6 +331,15 @@ module.exports.addTests = function({testRunner, expect, puppeteer, DeviceDescrip
|
|||||||
]);
|
]);
|
||||||
expect(message.text()).toBe('JSHandle@object');
|
expect(message.text()).toBe('JSHandle@object');
|
||||||
});
|
});
|
||||||
|
it('should trigger correct Log', async({page, server}) => {
|
||||||
|
await page.goto('about:blank');
|
||||||
|
let message;
|
||||||
|
page.on('console', event => message = event);
|
||||||
|
page.evaluate(async url => fetch(url).catch(e => {}), server.EMPTY_PAGE);
|
||||||
|
await waitEvent(page, 'console');
|
||||||
|
expect(message.text()).toContain('No \'Access-Control-Allow-Origin\'');
|
||||||
|
expect(message.type()).toEqual('error');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Page.Events.DOMContentLoaded', function() {
|
describe('Page.Events.DOMContentLoaded', function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user