mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: introduce sdkLanguage based userDataDir misuse error (#26894)
Fixes https://github.com/microsoft/playwright-python/issues/2059 --------- Signed-off-by: Max Schmitt <max@schmitt.mx> Co-authored-by: Dmitry Gozman <dgozman@gmail.com>
This commit is contained in:
parent
d79dad09e8
commit
f71df9fb50
@ -281,6 +281,19 @@ export abstract class BrowserType extends SdkObject {
|
||||
return { ...options, devtools, headless, downloadsPath, proxy };
|
||||
}
|
||||
|
||||
protected _createUserDataDirArgMisuseError(userDataDirArg: string): Error {
|
||||
switch (this.attribution.playwright.options.sdkLanguage) {
|
||||
case 'java':
|
||||
return new Error(`Pass userDataDir parameter to 'BrowserType.launchPersistentContext(userDataDir, options)' instead of specifying '${userDataDirArg}' argument`);
|
||||
case 'python':
|
||||
return new Error(`Pass user_data_dir parameter to 'browser_type.launch_persistent_context(user_data_dir, **kwargs)' instead of specifying '${userDataDirArg}' argument`);
|
||||
case 'csharp':
|
||||
return new Error(`Pass userDataDir parameter to 'BrowserType.LaunchPersistentContextAsync(userDataDir, options)' instead of specifying '${userDataDirArg}' argument`);
|
||||
default:
|
||||
return new Error(`Pass userDataDir parameter to 'browserType.launchPersistentContext(userDataDir, options)' instead of specifying '${userDataDirArg}' argument`);
|
||||
}
|
||||
}
|
||||
|
||||
abstract _defaultArgs(options: types.LaunchOptions, isPersistent: boolean, userDataDir: string): string[];
|
||||
abstract _connectToTransport(transport: ConnectionTransport, options: BrowserOptions): Promise<Browser>;
|
||||
abstract _amendEnvironment(env: Env, userDataDir: string, executable: string, browserArguments: string[]): Env;
|
||||
|
||||
@ -292,7 +292,7 @@ export class Chromium extends BrowserType {
|
||||
const { args = [], proxy } = options;
|
||||
const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir'));
|
||||
if (userDataDirArg)
|
||||
throw new Error('Pass userDataDir parameter to `browserType.launchPersistentContext(userDataDir, ...)` instead of specifying --user-data-dir argument');
|
||||
throw this._createUserDataDirArgMisuseError('--user-data-dir');
|
||||
if (args.find(arg => arg.startsWith('--remote-debugging-pipe')))
|
||||
throw new Error('Playwright manages remote debugging connection itself.');
|
||||
if (args.find(arg => !arg.startsWith('-')))
|
||||
|
||||
@ -64,7 +64,7 @@ export class Firefox extends BrowserType {
|
||||
const { args = [], headless } = options;
|
||||
const userDataDirArg = args.find(arg => arg.startsWith('-profile') || arg.startsWith('--profile'));
|
||||
if (userDataDirArg)
|
||||
throw new Error('Pass userDataDir parameter to `browserType.launchPersistentContext(userDataDir, ...)` instead of specifying --profile argument');
|
||||
throw this._createUserDataDirArgMisuseError('--profile');
|
||||
if (args.find(arg => arg.startsWith('-juggler')))
|
||||
throw new Error('Use the port parameter instead of -juggler argument');
|
||||
const firefoxArguments = ['-no-remote'];
|
||||
|
||||
@ -54,7 +54,7 @@ export class WebKit extends BrowserType {
|
||||
const { args = [], proxy, headless } = options;
|
||||
const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir'));
|
||||
if (userDataDirArg)
|
||||
throw new Error('Pass userDataDir parameter to `browserType.launchPersistentContext(userDataDir, ...)` instead of specifying --user-data-dir argument');
|
||||
throw this._createUserDataDirArgMisuseError('--user-data-dir');
|
||||
if (args.find(arg => !arg.startsWith('-')))
|
||||
throw new Error('Arguments can not specify page to be opened');
|
||||
const webkitArguments = ['--inspector-pipe'];
|
||||
|
||||
@ -38,7 +38,7 @@ it('should throw if userDataDir option is passed', async ({ browserType }) => {
|
||||
it('should throw if userDataDir is passed as an argument', async ({ browserType }) => {
|
||||
let waitError = null;
|
||||
await browserType.launch({ args: ['--user-data-dir=random-path', '--profile=random-path'] } as any).catch(e => waitError = e);
|
||||
expect(waitError.message).toContain('Pass userDataDir parameter to `browserType.launchPersistentContext');
|
||||
expect(waitError.message).toContain(`Pass userDataDir parameter to 'browserType.launchPersistentContext`);
|
||||
});
|
||||
|
||||
it('should throw if port option is passed', async ({ browserType }) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user