You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting user-agent via page.setUserAgent, then allow request interception via page.setRequestInterception(true) and surcharge headers with whatever you want.
Please include code that reproduces the issue.
var express = require('express');
const puppeteer = require('puppeteer');
(async () => {
//Set small express server to print headers
new Promise((resolve, reject) => {
let port = 3001;
let app = express();
app.use(express.json());
app.listen(port);
app.route('/test').get((req, res) => {
console.log(JSON.stringify(req.headers));
});
});
//Create browser
let puppeteerArgs = [
'--no-sandbox',
'--disable-setuid-sandbox',
'--enable-features=NetworkService'
];
let browser = await puppeteer.launch({
headless: true,
args: puppeteerArgs
});
//Create page and set user-agent and interception
var page = await browser.newPage();
await page.setUserAgent('newUserAgent');
await page.setRequestInterception(true);
page.on('request', request => {
request.continue({headers: {}});
});
//Call the api
await page.goto('http://localhost:3001/test');
})();
What is the expected result?
Printed headers object should contain the user-agent set by page.setUserAgent.
What happens instead?
Print headers object contains the puppeteer user-agent.
So we have to explicitely change it in the returned header of request.continue().
This should either be changed or written in the doc.
The text was updated successfully, but these errors were encountered:
aslushnikov
added a commit
to aslushnikov/puppeteer
that referenced
this issue
Nov 1, 2018
@aslushnikov With that example, I was showing that not overriding any fields in the headers still resulted to the userAgent header to be reinitialized as if no page.setUserAgent() were used.
That was not working because I wasn't following the correct pattern, as you show in your example, you have to reinject every property of the existing headers to the overriding header if you want to conserve them.
Following the new example you provided in the doc made it work. Thanks.
Steps to reproduce
Tell us about your environment:
What steps will reproduce the problem?
Setting user-agent via page.setUserAgent, then allow request interception via page.setRequestInterception(true) and surcharge headers with whatever you want.
Please include code that reproduces the issue.
What is the expected result?
Printed headers object should contain the user-agent set by page.setUserAgent.
What happens instead?
Print headers object contains the puppeteer user-agent.
So we have to explicitely change it in the returned header of request.continue().
This should either be changed or written in the doc.
The text was updated successfully, but these errors were encountered: