diff --git a/lib/Page.js b/lib/Page.js index 6f79e04a..e8cab309 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -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', diff --git a/test/test.js b/test/test.js index 50e232a2..a9230380 100644 --- a/test/test.js +++ b/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});