3

I've a puppeteer script which works as expected when it's headless:false mode with Google Chrome profile and executablePath because I need to keep all sessions and browser data every time when I use the script, it also has chrome extension which works on the script browser profile.

But when I only make change to headless:true mode, same script doesn't work as before, it doesn't remember all browser data(sessions), and doesn't recognize my browser extension.

Here is the script code,

const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())

const browser = await puppeteer.launch({
    headless: true,
    ignoreHTTPSErrors: true,
    executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    args: [
      '--user-data-dir=/Users/x/Library/Application Support/Google/Chrome/Profile 2',
      '--window-size=1920,1080',
      "--no-sandbox",
      //"--disable-setuid-sandbox",
      "--disable-dev-shm-usage",
      "--disable-gpu",
      "--disable-extensions",
      "--disable-dev-tools",
      "--disable-infobars",
      "--ignore-certificate-errors",
      "--enable-logging",
      "--v=1",
      '--disable-setuid-sandbox',
      '--disable-infobars',
      '--window-position=0,0',
      '--ignore-certifcate-errors',
      '--ignore-certifcate-errors-spki-list',
      '--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
    ]
  });
  const page = await browser.newPage();

Is there anyway that I can keep using my script with no problem on headless:true mode or should I run the script like browser open all the time on a VDS machine :/

Thanks.

Information

https://github.com/puppeteer/puppeteer/issues/921

blueway
  • 129
  • 7
  • Did you try `userDataDir`? I'm not sure if that's what you're trying to persist. – ggorlen Jul 23 '22 at 18:07
  • that value actually passed in args array as `--user-data-dir`, what I wanna do is keep browser data while it's `headless:true` too – blueway Jul 23 '22 at 18:17
  • Missed that, sorry. I wonder if using the Puppeteer convenience param matters (probably not, but can't hurt trying). I've never had a problem with headless or headful data dir (works both ways for me), but I always use the builtin wrapper rather than the command line flag. – ggorlen Jul 23 '22 at 18:19
  • In your way to use; can you keep browser data(sessions, extensions) at every time when you run the script? – blueway Jul 23 '22 at 18:23
  • Yep. But maybe there's some other factor at play. Your code seems like it should work either way, but I might just not know what I'm talking about. Anyway, I'd try [this](https://pptr.dev/api/puppeteer.browserlaunchargumentoptions.userdatadir) just to be sure. If it doesn't work, I don't know what to suggest next other than maybe try it on another domain to eliminate that as a factor. – ggorlen Jul 23 '22 at 18:31
  • I've also tried with that arg but was same result, could you show me how to run with builtin wrapper like you said? – blueway Jul 23 '22 at 18:36
  • `browser.launch({userDataDir: "path/to/data/dir"})` – ggorlen Jul 23 '22 at 19:03
  • That what I tried but was same result. – blueway Jul 23 '22 at 20:12
  • @ggorlen I found this lately https://github.com/puppeteer/puppeteer/issues/921, so this problem actually doesn't exist for you? – blueway Jul 25 '22 at 08:20

0 Answers0