Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/playwright-core/src/remote/playwrightServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class PlaywrightServer {
}

const isExtension = this._options.mode === 'extension';
launchOptions = filterLaunchOptions(launchOptions, isExtension || !!this._options.unsafe);
launchOptions = filterLaunchOptions(launchOptions, isExtension, !!this._options.unsafe);

// Always override artifacts dir with the one from server options.
if (this._options.artifactsDir)
Expand Down Expand Up @@ -365,7 +365,8 @@ function launchOptionsHash(options: LaunchOptionsWithTimeout) {
return JSON.stringify(copy);
}

function filterLaunchOptions(options: LaunchOptionsWithTimeout, allowUnsafe: boolean): LaunchOptionsWithTimeout {
function filterLaunchOptions(options: LaunchOptionsWithTimeout, isExtension: boolean, unsafe: boolean): LaunchOptionsWithTimeout {
const allowUnsafe = isExtension || unsafe;
return {
channel: options.channel,
args: allowUnsafe ? options.args : undefined,
Expand All @@ -379,7 +380,7 @@ function filterLaunchOptions(options: LaunchOptionsWithTimeout, allowUnsafe: boo
slowMo: options.slowMo,
executablePath: (isUnderTest() || allowUnsafe) ? options.executablePath : undefined,
downloadsPath: allowUnsafe ? options.downloadsPath : undefined,
artifactsDir: (isUnderTest() || allowUnsafe) ? options.artifactsDir : undefined,
artifactsDir: (isUnderTest() || isExtension) ? options.artifactsDir : undefined,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are splitting unsafe vs local-only, let's apply the same treatment to the downloadsPath.

};
}

Expand Down
4 changes: 3 additions & 1 deletion tests/config/remoteServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ export class RunServer implements PlaywrightServer {
private _process!: TestChildProcess;
_wsEndpoint!: string;

async start(childProcess: CommonFixtures['childProcess'], options?: { mode?: 'extension' | 'default', env?: NodeJS.ProcessEnv, artifactsDir?: string }) {
async start(childProcess: CommonFixtures['childProcess'], options?: { mode?: 'extension' | 'default', env?: NodeJS.ProcessEnv, artifactsDir?: string, unsafe?: boolean }) {
const command = ['node', path.join(__dirname, '..', '..', 'packages', 'playwright-core', 'cli.js'), 'run-server'];
if (options?.mode === 'extension')
command.push('--mode=extension');
if (options?.artifactsDir)
command.push(`--artifacts-dir=${options.artifactsDir}`);
if (options?.unsafe)
command.push('--unsafe');
this._process = childProcess({
command,
env: { NODE_OPTIONS: process.env.NODE_OPTIONS, ...options?.env },
Expand Down
25 changes: 25 additions & 0 deletions tests/library/browsertype-connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,31 @@ test('should refuse connecting when versions do not match', async ({ connect, ch
expect(error.message).toContain('client version: v' + getPlaywrightVersion(true));
});

test('should filter artifactsDir from unsafe launch options', async ({ connect, childProcess }, testInfo) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42394' });
const artifactsDir = testInfo.outputPath('artifacts');
fs.writeFileSync(artifactsDir, 'not a directory');
const server = new RunServer();
await server.start(childProcess, { unsafe: true, env: { PWTEST_UNDER_TEST: undefined } });
const browser = await connect(server.wsEndpoint(), {
headers: {
'x-playwright-launch-options': JSON.stringify({ artifactsDir }),
},
});
const context = await browser.newContext();
await context.tracing.start({ snapshots: true });
const page = await context.newPage();
await page.setContent('<div>hello</div>');
const tracePath = testInfo.outputPath('trace.zip');
await context.tracing.stop({ path: tracePath });
await context.close();
await browser.close();
await server.close();

const { actions } = await parseTraceRaw(tracePath);
expect(actions).toContain('Set content');
});

test('should timeout after redirect when connecting over http', async ({ connect, server }) => {
server.setRedirect('/connect/json', '/connect/slow');
let aborted = false;
Expand Down
Loading