Introduce Page.Events.Request
This patch introduces the 'request' event which is fired when page has initiated a request. The event dispatches an instance of Request class. References #26.
This commit is contained in:
parent
7b59a89695
commit
d5be1a6436
@ -17,7 +17,7 @@
|
||||
let fs = require('fs');
|
||||
let EventEmitter = require('events');
|
||||
let mime = require('mime');
|
||||
let {InterceptedRequest} = require('./Request');
|
||||
let {Request, InterceptedRequest} = require('./Request');
|
||||
let Navigator = require('./Navigator');
|
||||
let Dialog = require('./Dialog');
|
||||
let FrameManager = require('./FrameManager');
|
||||
@ -70,6 +70,7 @@ class Page extends EventEmitter {
|
||||
|
||||
client.on('Network.responseReceived', event => this.emit(Page.Events.ResponseReceived, event.response));
|
||||
client.on('Network.loadingFailed', event => this.emit(Page.Events.ResourceLoadingFailed, event));
|
||||
client.on('Network.requestWillBeSent', event => this.emit(Page.Events.Request, new Request(event.request)));
|
||||
client.on('Page.loadEventFired', event => this.emit(Page.Events.Load));
|
||||
|
||||
client.on('Network.requestIntercepted', event => this._onRequestIntercepted(event));
|
||||
@ -628,6 +629,7 @@ Page.Events = {
|
||||
ConsoleMessage: 'consolemessage',
|
||||
Dialog: 'dialog',
|
||||
Error: 'error',
|
||||
Request: 'request',
|
||||
ResourceLoadingFailed: 'resourceloadingfailed',
|
||||
ResponseReceived: 'responsereceived',
|
||||
FrameAttached: 'frameattached',
|
||||
|
10
test/test.js
10
test/test.js
@ -269,6 +269,16 @@ describe('Puppeteer', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Page.Events.Request', function() {
|
||||
it('should fire', SX(async function(done) {
|
||||
let requests = [];
|
||||
page.on('request', request => requests.push(request));
|
||||
await page.navigate(EMPTY_PAGE);
|
||||
expect(requests.length).toBe(1);
|
||||
expect(requests[0].url).toContain('empty.html');
|
||||
}));
|
||||
});
|
||||
|
||||
describe('Page.screenshot', function() {
|
||||
it('should work', SX(async function() {
|
||||
await page.setViewportSize({width: 500, height: 500});
|
||||
|
Loading…
Reference in New Issue
Block a user