Skip to content

userDataDir + headless = lost authorizationΒ #921

Closed
@vsemozhetbyt

Description

  • Puppeteer version: v0.12.0-alpha
  • Platform / OS version: Windows 7 x64
  • URLs (if applicable): any that needs authorization
  1. 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.

  1. 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=...
  1. 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 both headless: false and headless: true modes.

  • console.log(await page.cookies('https://twitter.com/')); contains many cookies in the headless: false mode. In the headless: true mode it gives an empty array [].

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions