fix: allow relative userDataDir (#34710)
This commit is contained in:
parent
72cd6f06aa
commit
416c9b3368
|
|
@ -14,6 +14,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
import { Browser } from './browser';
|
import { Browser } from './browser';
|
||||||
import { BrowserContext, prepareBrowserContextParams } from './browserContext';
|
import { BrowserContext, prepareBrowserContextParams } from './browserContext';
|
||||||
import { ChannelOwner } from './channelOwner';
|
import { ChannelOwner } from './channelOwner';
|
||||||
|
|
@ -98,7 +100,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
|
||||||
ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs),
|
ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs),
|
||||||
env: options.env ? envObjectToArray(options.env) : undefined,
|
env: options.env ? envObjectToArray(options.env) : undefined,
|
||||||
channel: options.channel,
|
channel: options.channel,
|
||||||
userDataDir,
|
userDataDir: path.isAbsolute(userDataDir) ? userDataDir : path.resolve(userDataDir),
|
||||||
};
|
};
|
||||||
return await this._wrapApiCall(async () => {
|
return await this._wrapApiCall(async () => {
|
||||||
const result = await this._channel.launchPersistentContext(persistentParams);
|
const result = await this._channel.launchPersistentContext(persistentParams);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import * as path from 'path';
|
||||||
|
|
||||||
import { normalizeProxySettings, validateBrowserContextOptions } from './browserContext';
|
import { normalizeProxySettings, validateBrowserContextOptions } from './browserContext';
|
||||||
import { DEFAULT_TIMEOUT, TimeoutSettings } from '../common/timeoutSettings';
|
import { DEFAULT_TIMEOUT, TimeoutSettings } from '../common/timeoutSettings';
|
||||||
import { ManualPromise, debugMode } from '../utils';
|
import { ManualPromise, assert, debugMode } from '../utils';
|
||||||
import { existsAsync } from './fileUtils';
|
import { existsAsync } from './fileUtils';
|
||||||
import { helper } from './helper';
|
import { helper } from './helper';
|
||||||
import { SdkObject } from './instrumentation';
|
import { SdkObject } from './instrumentation';
|
||||||
|
|
@ -188,6 +188,7 @@ export abstract class BrowserType extends SdkObject {
|
||||||
tempDirectories.push(artifactsDir);
|
tempDirectories.push(artifactsDir);
|
||||||
|
|
||||||
if (userDataDir) {
|
if (userDataDir) {
|
||||||
|
assert(path.isAbsolute(userDataDir), 'userDataDir must be an absolute path');
|
||||||
// Firefox bails if the profile directory does not exist, Chrome creates it. We ensure consistent behavior here.
|
// Firefox bails if the profile directory does not exist, Chrome creates it. We ensure consistent behavior here.
|
||||||
if (!await existsAsync(userDataDir))
|
if (!await existsAsync(userDataDir))
|
||||||
await fs.promises.mkdir(userDataDir, { recursive: true, mode: 0o700 });
|
await fs.promises.mkdir(userDataDir, { recursive: true, mode: 0o700 });
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,13 @@ it('should accept userDataDir', async ({ createUserDataDir, browserType }) => {
|
||||||
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should accept relative userDataDir', async ({ createUserDataDir, browserType }) => {
|
||||||
|
const userDataDir = await createUserDataDir();
|
||||||
|
const context = await browserType.launchPersistentContext(path.relative(process.cwd(), path.join(userDataDir, 'foobar')));
|
||||||
|
expect(fs.readdirSync(path.join(userDataDir, 'foobar')).length).toBeGreaterThan(0);
|
||||||
|
await context.close();
|
||||||
|
});
|
||||||
|
|
||||||
it('should restore state from userDataDir', async ({ browserType, server, createUserDataDir, isMac, browserName }) => {
|
it('should restore state from userDataDir', async ({ browserType, server, createUserDataDir, isMac, browserName }) => {
|
||||||
it.slow();
|
it.slow();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue