diff --git a/docs/api.md b/docs/api.md index fcc91136..d87a9368 100644 --- a/docs/api.md +++ b/docs/api.md @@ -742,7 +742,7 @@ Shortcut for [`keyboard.down`](#keyboarddownkey-options) and [`keyboard.up`](#ke - returns: <[Promise]> #### page.setExtraHTTPHeaders(headers) -- `headers` <[Object]> An object containing additional http headers to be sent with every request. +- `headers` <[Object]> An object containing additional http headers to be sent with every request. All header values must be strings. - returns: <[Promise]> The extra HTTP headers will be sent with every request the page initiates. diff --git a/lib/NetworkManager.js b/lib/NetworkManager.js index 78122edf..cabed313 100644 --- a/lib/NetworkManager.js +++ b/lib/NetworkManager.js @@ -63,8 +63,11 @@ class NetworkManager extends EventEmitter { */ async setExtraHTTPHeaders(extraHTTPHeaders) { this._extraHTTPHeaders = {}; - for (const key of Object.keys(extraHTTPHeaders)) - this._extraHTTPHeaders[key.toLowerCase()] = extraHTTPHeaders[key]; + for (const key of Object.keys(extraHTTPHeaders)) { + const value = extraHTTPHeaders[key]; + console.assert(helper.isString(value), `Expected value of header "${key}" to be String, but "${typeof value}" is found.`); + this._extraHTTPHeaders[key.toLowerCase()] = value; + } await this._client.send('Network.setExtraHTTPHeaders', { headers: this._extraHTTPHeaders }); } diff --git a/test/test.js b/test/test.js index fc3c1a6c..8f521aa4 100644 --- a/test/test.js +++ b/test/test.js @@ -1538,6 +1538,15 @@ describe('Page', function() { ]); expect(request.headers['foo']).toBe('bar'); })); + it('should throw for non-string header values', SX(async function() { + let error = null; + try { + await page.setExtraHTTPHeaders({ 'foo': 1 }); + } catch (e) { + error = e; + } + expect(error.message).toBe('Expected value of header "foo" to be String, but "number" is found.'); + })); }); describe('Page.authenticate', function() { it('should work', SX(async function() {