puppeteer userdatadir crashing browser

Viewed 459

I'm building a script with puppeteer to do a Youtube login. I wanted my login session saved with userDataDir when I open firefox with puppeteer. However, adding the userDataDir argument is crashing my browser launch.

const browser = await puppeteer.launch({
            product: 'firefox',
            args: [
                  '-wait-for-browser',
                   "--no-sandbox"
                  ],
            headless: true,
            userDataDir: "./user_data",
            dumpio: true
        });
    

The error I'm getting is this:

Users/calvinchen/node_modules/puppeteer/lib/cjs/common/Connection.js:54
        this._callbacks.set(id, { resolve, reject, error: new Error(), method });
                                                              ^

Error: Protocol error (Target.setDiscoverTargets): can't access property "currentWindowGlobal", this.browsingContext is null get title@chrome://remote/content/targets/TabTarget.jsm:111:5
_getTargetInfo@chrome://remote/content/domains/parent/Target.jsm:181:7
_onTargetCreated@chrome://remote/content/domains/parent/Target.jsm:190:29
setDiscoverTargets@chrome://remote/content/domains/parent/Target.jsm:91:12
execute@chrome://remote/content/domains/DomainCache.jsm:99:25
execute@chrome://remote/content/sessions/Session.jsm:64:25
onPacket@chrome://remote/content/Connection.jsm:225:36
onMessage@chrome://remote/content/server/WebSocketTransport.jsm:85:18
handleEvent@chrome://remote/content/server/WebSocketTransport.jsm:67:14

at /Users/calvinchen/node_modules/puppeteer/lib/cjs/common/Connection.js:54:63
at new Promise (<anonymous>)
at Connection.send (/Users/calvinchen/node_modules/puppeteer/lib/cjs/common/Connection.js:53:16)
at Function.create (/Users/calvinchen/node_modules/puppeteer/lib/cjs/common/Browser.js:90:26)
at FirefoxLauncher.launch (/Users/calvinchen/node_modules/puppeteer/lib/cjs/node/Launcher.js:238:53)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async /Users/calvinchen/Desktop/YoutubeUploaderV2/youtubeuploader.js:32:21

When I commented out the userdatadir and the browser launches as intended.

2 Answers

I had the same problem with Firefox. It looks like if the user data gets corrupted if you don't close the browser properly. I turned headless off and then manually closed the browser when I was done. Then, my user data never got corrupted again.

Try running without headless set to false. I had similar issue, but for some reason running with headless: false fixed the issue.

Related