Playwright: [Question] Error: userDataDir option is not supported in `browserType.launch`.

Created on 17 Feb 2020  路  3Comments  路  Source: microsoft/playwright

I have two computer both on windows 10 x64
On the first of them, such code does not cause any errors

const args = [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-infobars',
        '--window-position=0,0',
        '--ignore-certifcate-errors',
        '--ignore-certifcate-errors-spki-list',
];
const options = {
            args,
            headless: false,
            ignoreHTTPSErrors: true,
            userDataDir: './tmp'
        };      
    const browser = await chromium.launch(options);

And on the second I get an error

(node:6208) UnhandledPromiseRejectionWarning: Error: userDataDir option is not supported in browserType.launch. Use browserType.launchPersistent instead
at Chromium.launch (C:\nodejs\telegram\node_modules\playwright-core\lib\server\chromium.js:44:19)

Most helpful comment

launchPersistent returns a context, so actually it is:

const context = await chromium.launchPersistent('./tmp', options);
const page = await context.newPage();

Apparently it's an issue in the docs. I'll open a PR for it. LE: done, #1047

All 3 comments

See https://github.com/microsoft/playwright/pull/974:

userDataDir option is not supported in browserType.launch. Use browserType.launchPersistent instead

As the error describes, you should use .launchPersistent instead of .launch

Most likely on one of the computers you have an older version of playwright (pre-#974)

You can show an example of how to use .launchPersistent with option userDataDir
I try to replace
const browser = await chromium.launch(options);
to this

const browser = await chromium.launchPersistent('./tmp', options);
const context = await browser.newContext();

and I get follow error
(node:11252) UnhandledPromiseRejectionWarning: TypeError: browser.newContext is not a function

I looked at the documentation method launchPersistent returns: Promise BrowserServer
While the method launch returns: Promise Browser

launchPersistent returns a context, so actually it is:

const context = await chromium.launchPersistent('./tmp', options);
const page = await context.newPage();

Apparently it's an issue in the docs. I'll open a PR for it. LE: done, #1047

Was this page helpful?
0 / 5 - 0 ratings