diff --git a/docs/api.md b/docs/api.md index 29a09cb8264..c598b90a511 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1318,6 +1318,7 @@ Navigate to the next page in history. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. - `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. + - `referer` <[string]> Referer header value. If provided it will take prefrence over the referer header value set by [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders). - returns: <[Promise]> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. The `page.goto` will throw an error if: diff --git a/lib/Page.js b/lib/Page.js index 4ba3ef840d0..e53cb672eb7 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -577,7 +577,7 @@ class Page extends EventEmitter { * @return {!Promise} */ async goto(url, options = {}) { - const referrer = this._networkManager.extraHTTPHeaders()['referer']; + const referrer = typeof options.referer === 'string' ? options.referer : this._networkManager.extraHTTPHeaders()['referer']; /** @type {Map} */ const requests = new Map(); diff --git a/test/page.spec.js b/test/page.spec.js index 0a4abf792a0..66189b10999 100644 --- a/test/page.spec.js +++ b/test/page.spec.js @@ -754,6 +754,17 @@ module.exports.addTests = function({testRunner, expect, headless}) { } expect(error.message).toContain(url); }); + it('should send referer', async({page, server}) => { + await page.setRequestInterception(true); + page.on('request', request => request.continue()); + const [request] = await Promise.all([ + server.waitForRequest('/grid.html'), + page.goto(server.PREFIX + '/grid.html', { + referer: 'http://google.com/', + }), + ]); + expect(request.headers['referer']).toBe('http://google.com/'); + }); }); describe('Page.waitForNavigation', function() {