mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(webkit): introduce user-data-dir and use it on win (#505)
This commit is contained in:
parent
dae6e7cabc
commit
2a619db582
@ -24,25 +24,34 @@ import { WKConnectOptions } from '../webkit/wkBrowser';
|
|||||||
import { execSync, ChildProcess } from 'child_process';
|
import { execSync, ChildProcess } from 'child_process';
|
||||||
import { PipeTransport } from './pipeTransport';
|
import { PipeTransport } from './pipeTransport';
|
||||||
import { launchProcess } from './processLauncher';
|
import { launchProcess } from './processLauncher';
|
||||||
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as platform from '../platform';
|
||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import { assert } from '../helper';
|
import { assert } from '../helper';
|
||||||
import { kBrowserCloseMessageId } from '../webkit/wkConnection';
|
import { kBrowserCloseMessageId } from '../webkit/wkConnection';
|
||||||
import { Playwright } from './playwright';
|
import { Playwright } from './playwright';
|
||||||
|
|
||||||
export type LaunchOptions = {
|
export type SlowMoOptions = {
|
||||||
ignoreDefaultArgs?: boolean | string[],
|
slowMo?: number,
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WebKitArgOptions = {
|
||||||
|
headless?: boolean,
|
||||||
args?: string[],
|
args?: string[],
|
||||||
|
userDataDir?: string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LaunchOptions = WebKitArgOptions & SlowMoOptions & {
|
||||||
executablePath?: string,
|
executablePath?: string,
|
||||||
|
ignoreDefaultArgs?: boolean | string[],
|
||||||
handleSIGINT?: boolean,
|
handleSIGINT?: boolean,
|
||||||
handleSIGTERM?: boolean,
|
handleSIGTERM?: boolean,
|
||||||
handleSIGHUP?: boolean,
|
handleSIGHUP?: boolean,
|
||||||
headless?: boolean,
|
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
dumpio?: boolean,
|
dumpio?: boolean,
|
||||||
env?: {[key: string]: string} | undefined,
|
env?: {[key: string]: string} | undefined,
|
||||||
slowMo?: number,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export class WKBrowserServer {
|
export class WKBrowserServer {
|
||||||
@ -111,6 +120,17 @@ export class WKPlaywright implements Playwright {
|
|||||||
else
|
else
|
||||||
webkitArguments.push(...args);
|
webkitArguments.push(...args);
|
||||||
|
|
||||||
|
let userDataDir: string;
|
||||||
|
let temporaryUserDataDir: string | null = null;
|
||||||
|
const userDataDirArg = webkitArguments.find(arg => arg.startsWith('--user-data-dir'));
|
||||||
|
if (userDataDirArg) {
|
||||||
|
userDataDir = userDataDirArg.substr('--user-data-dir'.length).trim();
|
||||||
|
} else {
|
||||||
|
userDataDir = await mkdtempAsync(WEBKIT_PROFILE_PATH);
|
||||||
|
temporaryUserDataDir = userDataDir;
|
||||||
|
webkitArguments.push(`--user-data-dir=${temporaryUserDataDir}`);
|
||||||
|
}
|
||||||
|
|
||||||
let webkitExecutable = executablePath;
|
let webkitExecutable = executablePath;
|
||||||
if (!executablePath) {
|
if (!executablePath) {
|
||||||
const {missingText, executablePath} = this._resolveExecutablePath();
|
const {missingText, executablePath} = this._resolveExecutablePath();
|
||||||
@ -127,12 +147,13 @@ export class WKPlaywright implements Playwright {
|
|||||||
const { launchedProcess, gracefullyClose } = await launchProcess({
|
const { launchedProcess, gracefullyClose } = await launchProcess({
|
||||||
executablePath: webkitExecutable!,
|
executablePath: webkitExecutable!,
|
||||||
args: webkitArguments,
|
args: webkitArguments,
|
||||||
env,
|
env: { ...env, CURL_COOKIE_JAR_PATH: path.join(userDataDir, 'cookiejar.db') },
|
||||||
handleSIGINT,
|
handleSIGINT,
|
||||||
handleSIGTERM,
|
handleSIGTERM,
|
||||||
handleSIGHUP,
|
handleSIGHUP,
|
||||||
dumpio,
|
dumpio,
|
||||||
pipe: true,
|
pipe: true,
|
||||||
|
tempDir: temporaryUserDataDir || undefined,
|
||||||
attemptToGracefullyClose: async () => {
|
attemptToGracefullyClose: async () => {
|
||||||
if (!connectOptions)
|
if (!connectOptions)
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
@ -160,11 +181,14 @@ export class WKPlaywright implements Playwright {
|
|||||||
return { TimeoutError };
|
return { TimeoutError };
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultArgs(options: { args?: string[] } = {}): string[] {
|
defaultArgs(options: WebKitArgOptions = {}): string[] {
|
||||||
const {
|
const {
|
||||||
args = [],
|
args = [],
|
||||||
|
userDataDir = null
|
||||||
} = options;
|
} = options;
|
||||||
const webkitArguments = [...DEFAULT_ARGS];
|
const webkitArguments = [...DEFAULT_ARGS];
|
||||||
|
if (userDataDir)
|
||||||
|
webkitArguments.push(`--user-data-dir=${userDataDir}`);
|
||||||
webkitArguments.push(...args);
|
webkitArguments.push(...args);
|
||||||
return webkitArguments;
|
return webkitArguments;
|
||||||
}
|
}
|
||||||
@ -214,6 +238,9 @@ export class WKPlaywright implements Playwright {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mkdtempAsync = platform.promisify(fs.mkdtemp);
|
||||||
|
|
||||||
|
const WEBKIT_PROFILE_PATH = path.join(os.tmpdir(), 'playwright_dev_profile-');
|
||||||
const DEFAULT_ARGS: string[] = [];
|
const DEFAULT_ARGS: string[] = [];
|
||||||
|
|
||||||
let cachedMacVersion: string | undefined = undefined;
|
let cachedMacVersion: string | undefined = undefined;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user