Closed
Description
- Puppeteer version: v0.12.0-alpha
- Platform / OS version: Windows 7 x64
- URLs (if applicable): any that needs authorization
- Create a test script and an empty folder
test-profile-dir
:
'use strict';
const puppeteer = require('puppeteer');
(async function main() {
try {
const browser = await puppeteer.launch({
headless: false,
userDataDir: 'test-profile-dir',
});
const page = await browser.newPage();
await page.goto('https://twitter.com/');
console.log(await page.evaluate(() => document.title));
console.log(await page.evaluate(() => document.cookie));
// await browser.close();
} catch (err) {
console.error(err);
}
})();
You will see something like this:
Twitter. It's what's happening.
personalization_id=...; guest_id=...; ct0=...
Sign in into Twitter and close the browser.
- Run the same script second time (
await browser.close();
can be uncommented). You will see something like this:
Twitter
personalization_id=...; guest_id=...; ct0=...; ads_prefs=...; remember_checked_on=...;
twid=...; tip_nightmode=...; _ga=...; _gid=...; dnt=...; lang=...
- Run the same script, but with
headless: true,
The output is the same as before authorization:
Twitter. It's what's happening.
personalization_id=...; guest_id=...; ct0=...
I have tried various sites, all of them seem to lose authorization in headless mode.
Some more notes:
-
response.request().headers
does not contain cookies in bothheadless: false
andheadless: true
modes. -
console.log(await page.cookies('https://twitter.com/'));
contains many cookies in theheadless: false
mode. In theheadless: true
mode it gives an empty array[]
.