From fbf36438e8502ef37b4be2819afa67a595410d68 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 13 Feb 2019 13:11:50 -0800 Subject: [PATCH] feat(firefox): support Request.postData (#3999) --- .../puppeteer-firefox/lib/NetworkManager.js | 5 ++++ experimental/puppeteer-firefox/package.json | 2 +- test/network.spec.js | 25 ++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/experimental/puppeteer-firefox/lib/NetworkManager.js b/experimental/puppeteer-firefox/lib/NetworkManager.js index 0d983e0059f..9daaaf9d0d3 100644 --- a/experimental/puppeteer-firefox/lib/NetworkManager.js +++ b/experimental/puppeteer-firefox/lib/NetworkManager.js @@ -99,6 +99,7 @@ class Request { this._id = payload.requestId; this._redirectChain = redirectChain; this._url = payload.url; + this._postData = payload.postData; this._response = null; this._isNavigationRequest = payload.isNavigationRequest; this._method = payload.method; @@ -108,6 +109,10 @@ class Request { this._headers[name.toLowerCase()] = value; } + postData() { + return this._postData; + } + headers() { return {...this._headers}; } diff --git a/experimental/puppeteer-firefox/package.json b/experimental/puppeteer-firefox/package.json index 12a4a6ede78..a381588fa77 100644 --- a/experimental/puppeteer-firefox/package.json +++ b/experimental/puppeteer-firefox/package.json @@ -9,7 +9,7 @@ "node": ">=8.9.4" }, "puppeteer": { - "firefox_revision": "ac50a00d0cb3522407d3c84ec85360cbc4d14c9c" + "firefox_revision": "32fc518d9228fd0115c0a4fd4bd341780bdba2fc" }, "scripts": { "install": "node install.js", diff --git a/test/network.spec.js b/test/network.spec.js index 4b138f5efdf..9aba5cff0ad 100644 --- a/test/network.spec.js +++ b/test/network.spec.js @@ -140,6 +140,22 @@ module.exports.addTests = function({testRunner, expect, CHROME}) { }); }); + describe('Request.postData', function() { + it('should work', async({page, server}) => { + await page.goto(server.EMPTY_PAGE); + server.setRoute('/post', (req, res) => res.end()); + let request = null; + page.on('request', r => request = r); + await page.evaluate(() => fetch('./post', { method: 'POST', body: JSON.stringify({foo: 'bar'})})); + expect(request).toBeTruthy(); + expect(request.postData()).toBe('{"foo":"bar"}'); + }); + it('should be |undefined| when there is no post data', async({page, server}) => { + const response = await page.goto(server.EMPTY_PAGE); + expect(response.request().postData()).toBe(undefined); + }); + }); + describe('Network Events', function() { it('Page.Events.Request', async({page, server}) => { const requests = []; @@ -153,15 +169,6 @@ module.exports.addTests = function({testRunner, expect, CHROME}) { expect(requests[0].frame() === page.mainFrame()).toBe(true); expect(requests[0].frame().url()).toBe(server.EMPTY_PAGE); }); - it_fails_ffox('Page.Events.Request should report post data', async({page, server}) => { - await page.goto(server.EMPTY_PAGE); - server.setRoute('/post', (req, res) => res.end()); - let request = null; - page.on('request', r => request = r); - await page.evaluate(() => fetch('./post', { method: 'POST', body: JSON.stringify({foo: 'bar'})})); - expect(request).toBeTruthy(); - expect(request.postData()).toBe('{"foo":"bar"}'); - }); it('Page.Events.Response', async({page, server}) => { const responses = []; page.on('response', response => responses.push(response));