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)
See https://github.com/microsoft/playwright/pull/974:
userDataDir option is not supported in
browserType.launch. UsebrowserType.launchPersistentinstead
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
Most helpful comment
launchPersistentreturns a context, so actually it is:Apparently it's an issue in the docs. I'll open a PR for it. LE: done, #1047