Skip to content

Commit 4a77363

Browse files
authored
api: update videos api, hide tracing (#4015)
1 parent 920cc7c commit 4a77363

File tree

20 files changed

+146
-146
lines changed

20 files changed

+146
-146
lines changed

docs/api.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,10 @@ Indicates that the browser is connected.
220220
- `password` <[string]>
221221
- `colorScheme` <"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'.
222222
- `logger` <[Logger]> Logger sink for Playwright logging.
223-
- `relativeArtifactsPath` <[string]> Specifies a folder for artifacts like downloads, videos and traces, relative to `artifactsPath` from [`browserType.launch`](#browsertypelaunchoptions). Defaults to `.`.
224-
- `recordVideos` <[boolean]> Enables video recording for all pages to the `relativeArtifactsPath` folder.
225-
- `videoSize` <[Object]> Specifies dimensions of the automatically recorded video. Can only be used if `recordVideos` is true. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
223+
- `videosPath` <[string]> Enables video recording for all pages to `videosPath` folder. If not specified, videos are not recorded.
224+
- `videoSize` <[Object]> Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
226225
- `width` <[number]> Video frame width.
227226
- `height` <[number]> Video frame height.
228-
- `recordTrace` <[boolean]> Enables trace recording to the `relativeArtifactsPath` folder.
229227
- returns: <[Promise]<[BrowserContext]>>
230228

231229
Creates a new browser context. It won't share cookies/cache with other browser contexts.
@@ -268,12 +266,10 @@ Creates a new browser context. It won't share cookies/cache with other browser c
268266
- `password` <[string]>
269267
- `colorScheme` <"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'.
270268
- `logger` <[Logger]> Logger sink for Playwright logging.
271-
- `relativeArtifactsPath` <[string]> Specifies a folder for artifacts like downloads, videos and traces, relative to `artifactsPath` from [`browserType.launch`](#browsertypelaunchoptions). Defaults to `.`.
272-
- `recordVideos` <[boolean]> Enables video recording for all pages to the `relativeArtifactsPath` folder.
273-
- `videoSize` <[Object]> Specifies dimensions of the automatically recorded video. Can only be used if `recordVideos` is true. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
269+
- `videosPath` <[string]> Enables video recording for all pages to `videosPath` folder. If not specified, videos are not recorded.
270+
- `videoSize` <[Object]> Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
274271
- `width` <[number]> Video frame width.
275272
- `height` <[number]> Video frame height.
276-
- `recordTrace` <[boolean]> Enables trace recording to the `relativeArtifactsPath` folder.
277273
- returns: <[Promise]<[Page]>>
278274

279275
Creates a new page in a new browser context. Closing this page will close the context as well.
@@ -4174,7 +4170,6 @@ This methods attaches Playwright to an existing browser instance.
41744170
- `username` <[string]> Optional username to use if HTTP proxy requires authentication.
41754171
- `password` <[string]> Optional password to use if HTTP proxy requires authentication.
41764172
- `downloadsPath` <[string]> If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
4177-
- `artifactsPath` <[string]> Specifies a folder for various artifacts like downloads, videos and traces. If not specified, artifacts are not collected.
41784173
- `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `true`.
41794174
- `firefoxUserPrefs` <[Object]<[string], [string]|[number]|[boolean]>> Firefox user preferences. Learn more about the Firefox user preferences at [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
41804175
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
@@ -4217,7 +4212,6 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
42174212
- `password` <[string]> Optional password to use if HTTP proxy requires authentication.
42184213
- `acceptDownloads` <[boolean]> Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
42194214
- `downloadsPath` <[string]> If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
4220-
- `artifactsPath` <[string]> Specifies a folder for various artifacts like downloads, videos and traces. If not specified, artifacts are not collected.
42214215
- `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `true`.
42224216
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
42234217
- `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.
@@ -4250,12 +4244,10 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
42504244
- `username` <[string]>
42514245
- `password` <[string]>
42524246
- `colorScheme` <"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'.
4253-
- `relativeArtifactsPath` <[string]> Specifies a folder for artifacts like downloads, videos and traces, relative to `artifactsPath`. Defaults to `.`.
4254-
- `recordVideos` <[boolean]> Enables video recording for all pages to the `relativeArtifactsPath` folder.
4255-
- `videoSize` <[Object]> Specifies dimensions of the automatically recorded video. Can only be used if `recordVideos` is true. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
4247+
- `videosPath` <[string]> Enables video recording for all pages to `videosPath` folder. If not specified, videos are not recorded.
4248+
- `videoSize` <[Object]> Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size.
42564249
- `width` <[number]> Video frame width.
42574250
- `height` <[number]> Video frame height.
4258-
- `recordTrace` <[boolean]> Enables trace recording to the `relativeArtifactsPath` folder.
42594251
- returns: <[Promise]<[BrowserContext]>> Promise that resolves to the persistent browser context instance.
42604252

42614253
Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing this context will automatically close the browser.
@@ -4273,7 +4265,6 @@ Launches browser that uses persistent storage located at `userDataDir` and retur
42734265
- `username` <[string]> Optional username to use if HTTP proxy requires authentication.
42744266
- `password` <[string]> Optional password to use if HTTP proxy requires authentication.
42754267
- `downloadsPath` <[string]> If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
4276-
- `artifactsPath` <[string]> Specifies a folder for various artifacts like downloads, videos and traces. If not specified, artifacts are not collected.
42774268
- `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `true`.
42784269
- `firefoxUserPrefs` <[Object]<[string], [string]|[number]|[boolean]>> Firefox user preferences. Learn more about the Firefox user preferences at [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
42794270
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.

packages/installation-tests/screencast.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ if (process.argv[3] === 'all')
2727
success = ['chromium', 'firefox', 'webkit'];
2828

2929
const playwright = require(requireName);
30-
const path = require('path');
3130
const fs = require('fs');
3231

3332
(async () => {
3433
for (const browserType of success) {
3534
try {
36-
const browser = await playwright[browserType].launch({
37-
artifactsPath: __dirname,
38-
});
35+
const browser = await playwright[browserType].launch({});
3936
const context = await browser.newContext({
40-
recordVideos: true,
37+
videosPath: __dirname,
4138
videoSize: {width: 320, height: 240},
4239
});
4340
await context.newPage();

src/client/browser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export class Browser extends ChannelOwner<channels.BrowserChannel, channels.Brow
4747
async newContext(options: BrowserContextOptions = {}): Promise<BrowserContext> {
4848
const logger = options.logger;
4949
return this._wrapApiCall('browser.newContext', async () => {
50+
if (this._isRemote && options.videosPath)
51+
throw new Error(`"videosPath" is not supported in connected browser`);
52+
if (this._isRemote && options._tracePath)
53+
throw new Error(`"_tracePath" is not supported in connected browser`);
5054
if (options.extraHTTPHeaders)
5155
validateHeaders(options.extraHTTPHeaders);
5256
const contextOptions: channels.BrowserNewContextParams = {

src/client/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export type LaunchServerOptions = {
8282
password?: string
8383
},
8484
downloadsPath?: string,
85-
artifactsPath?: string,
8685
chromiumSandbox?: boolean,
8786
port?: number,
8887
logger?: Logger,

src/protocol/channels.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ export type BrowserTypeLaunchParams = {
168168
password?: string,
169169
},
170170
downloadsPath?: string,
171-
artifactsPath?: string,
172171
firefoxUserPrefs?: any,
173172
chromiumSandbox?: boolean,
174173
slowMo?: number,
@@ -195,7 +194,6 @@ export type BrowserTypeLaunchOptions = {
195194
password?: string,
196195
},
197196
downloadsPath?: string,
198-
artifactsPath?: string,
199197
firefoxUserPrefs?: any,
200198
chromiumSandbox?: boolean,
201199
slowMo?: number,
@@ -226,7 +224,6 @@ export type BrowserTypeLaunchPersistentContextParams = {
226224
password?: string,
227225
},
228226
downloadsPath?: string,
229-
artifactsPath?: string,
230227
chromiumSandbox?: boolean,
231228
slowMo?: number,
232229
noDefaultViewport?: boolean,
@@ -260,8 +257,13 @@ export type BrowserTypeLaunchPersistentContextParams = {
260257
hasTouch?: boolean,
261258
colorScheme?: 'light' | 'dark' | 'no-preference',
262259
acceptDownloads?: boolean,
263-
relativeArtifactsPath?: string,
264-
recordTrace?: boolean,
260+
_traceResourcesPath?: string,
261+
_tracePath?: string,
262+
videosPath?: string,
263+
videoSize?: {
264+
width: number,
265+
height: number,
266+
},
265267
};
266268
export type BrowserTypeLaunchPersistentContextOptions = {
267269
executablePath?: string,
@@ -285,7 +287,6 @@ export type BrowserTypeLaunchPersistentContextOptions = {
285287
password?: string,
286288
},
287289
downloadsPath?: string,
288-
artifactsPath?: string,
289290
chromiumSandbox?: boolean,
290291
slowMo?: number,
291292
noDefaultViewport?: boolean,
@@ -319,8 +320,13 @@ export type BrowserTypeLaunchPersistentContextOptions = {
319320
hasTouch?: boolean,
320321
colorScheme?: 'light' | 'dark' | 'no-preference',
321322
acceptDownloads?: boolean,
322-
relativeArtifactsPath?: string,
323-
recordTrace?: boolean,
323+
_traceResourcesPath?: string,
324+
_tracePath?: string,
325+
videosPath?: string,
326+
videoSize?: {
327+
width: number,
328+
height: number,
329+
},
324330
};
325331
export type BrowserTypeLaunchPersistentContextResult = {
326332
context: BrowserContextChannel,
@@ -375,9 +381,9 @@ export type BrowserNewContextParams = {
375381
hasTouch?: boolean,
376382
colorScheme?: 'dark' | 'light' | 'no-preference',
377383
acceptDownloads?: boolean,
378-
relativeArtifactsPath?: string,
379-
recordTrace?: boolean,
380-
recordVideos?: boolean,
384+
_traceResourcesPath?: string,
385+
_tracePath?: string,
386+
videosPath?: string,
381387
videoSize?: {
382388
width: number,
383389
height: number,
@@ -415,9 +421,9 @@ export type BrowserNewContextOptions = {
415421
hasTouch?: boolean,
416422
colorScheme?: 'dark' | 'light' | 'no-preference',
417423
acceptDownloads?: boolean,
418-
relativeArtifactsPath?: string,
419-
recordTrace?: boolean,
420-
recordVideos?: boolean,
424+
_traceResourcesPath?: string,
425+
_tracePath?: string,
426+
videosPath?: string,
421427
videoSize?: {
422428
width: number,
423429
height: number,

src/protocol/protocol.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ BrowserType:
220220
username: string?
221221
password: string?
222222
downloadsPath: string?
223-
artifactsPath: string?
224223
firefoxUserPrefs: json?
225224
chromiumSandbox: boolean?
226225
slowMo: number?
@@ -259,7 +258,6 @@ BrowserType:
259258
username: string?
260259
password: string?
261260
downloadsPath: string?
262-
artifactsPath: string?
263261
chromiumSandbox: boolean?
264262
slowMo: number?
265263
noDefaultViewport: boolean?
@@ -306,8 +304,14 @@ BrowserType:
306304
- dark
307305
- no-preference
308306
acceptDownloads: boolean?
309-
relativeArtifactsPath: string?
310-
recordTrace: boolean?
307+
_traceResourcesPath: string?
308+
_tracePath: string?
309+
videosPath: string?
310+
videoSize:
311+
type: object?
312+
properties:
313+
width: number
314+
height: number
311315
returns:
312316
context: BrowserContext
313317

@@ -369,9 +373,9 @@ Browser:
369373
- light
370374
- no-preference
371375
acceptDownloads: boolean?
372-
relativeArtifactsPath: string?
373-
recordTrace: boolean?
374-
recordVideos: boolean?
376+
_traceResourcesPath: string?
377+
_tracePath: string?
378+
videosPath: string?
375379
videoSize:
376380
type: object?
377381
properties:

src/protocol/validator.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
121121
password: tOptional(tString),
122122
})),
123123
downloadsPath: tOptional(tString),
124-
artifactsPath: tOptional(tString),
125124
firefoxUserPrefs: tOptional(tAny),
126125
chromiumSandbox: tOptional(tBoolean),
127126
slowMo: tOptional(tNumber),
@@ -149,7 +148,6 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
149148
password: tOptional(tString),
150149
})),
151150
downloadsPath: tOptional(tString),
152-
artifactsPath: tOptional(tString),
153151
chromiumSandbox: tOptional(tBoolean),
154152
slowMo: tOptional(tNumber),
155153
noDefaultViewport: tOptional(tBoolean),
@@ -183,8 +181,13 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
183181
hasTouch: tOptional(tBoolean),
184182
colorScheme: tOptional(tEnum(['light', 'dark', 'no-preference'])),
185183
acceptDownloads: tOptional(tBoolean),
186-
relativeArtifactsPath: tOptional(tString),
187-
recordTrace: tOptional(tBoolean),
184+
_traceResourcesPath: tOptional(tString),
185+
_tracePath: tOptional(tString),
186+
videosPath: tOptional(tString),
187+
videoSize: tOptional(tObject({
188+
width: tNumber,
189+
height: tNumber,
190+
})),
188191
});
189192
scheme.BrowserCloseParams = tOptional(tObject({}));
190193
scheme.BrowserNewContextParams = tObject({
@@ -219,9 +222,9 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
219222
hasTouch: tOptional(tBoolean),
220223
colorScheme: tOptional(tEnum(['dark', 'light', 'no-preference'])),
221224
acceptDownloads: tOptional(tBoolean),
222-
relativeArtifactsPath: tOptional(tString),
223-
recordTrace: tOptional(tBoolean),
224-
recordVideos: tOptional(tBoolean),
225+
_traceResourcesPath: tOptional(tString),
226+
_tracePath: tOptional(tString),
227+
videosPath: tOptional(tString),
225228
videoSize: tOptional(tObject({
226229
width: tNumber,
227230
height: tNumber,

src/server/browser.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export interface BrowserProcess {
3131

3232
export type BrowserOptions = types.UIOptions & {
3333
name: string,
34-
artifactsPath?: string,
3534
downloadsPath?: string,
3635
headful?: boolean,
3736
persistent?: types.BrowserContextOptions, // Undefined means no persistent context.

src/server/browserContext.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,13 @@ export abstract class BrowserContext extends EventEmitter {
9494
readonly _browserContextId: string | undefined;
9595
private _selectors?: Selectors;
9696
readonly _actionListeners = new Set<ActionListener>();
97-
readonly _artifactsPath?: string;
9897

9998
constructor(browser: Browser, options: types.BrowserContextOptions, browserContextId: string | undefined) {
10099
super();
101100
this._browser = browser;
102101
this._options = options;
103102
this._browserContextId = browserContextId;
104103
this._isPersistentContext = !browserContextId;
105-
if (browser._options.artifactsPath) {
106-
this._artifactsPath = browser._options.artifactsPath;
107-
if (options.relativeArtifactsPath)
108-
this._artifactsPath = path.join(this._artifactsPath, options.relativeArtifactsPath);
109-
}
110104
this._closePromise = new Promise(fulfill => this._closePromiseFulfill = fulfill);
111105
}
112106

@@ -123,9 +117,9 @@ export abstract class BrowserContext extends EventEmitter {
123117
await listener.onContextCreated(this);
124118
}
125119

126-
async _ensureArtifactsPath() {
127-
if (this._artifactsPath)
128-
await mkdirIfNeeded(path.join(this._artifactsPath, 'dummy'));
120+
async _ensureVideosPath() {
121+
if (this._options.videosPath)
122+
await mkdirIfNeeded(path.join(this._options.videosPath, 'dummy'));
129123
}
130124

131125
_browserClosed() {
@@ -299,10 +293,8 @@ export function validateBrowserContextOptions(options: types.BrowserContextOptio
299293
if (!options.viewport && !options.noDefaultViewport)
300294
options.viewport = { width: 1280, height: 720 };
301295
verifyGeolocation(options.geolocation);
302-
if (options.recordTrace && !browserOptions.artifactsPath)
303-
throw new Error(`"recordTrace" option requires "artifactsPath" to be specified`);
304-
if (options.recordVideos && !browserOptions.artifactsPath)
305-
throw new Error(`"recordVideos" option requires "artifactsPath" to be specified`);
296+
if (options.videoSize && !options.videosPath)
297+
throw new Error(`"videoSize" option requires "videosPath" to be specified`);
306298
}
307299

308300
export function verifyGeolocation(geolocation?: types.Geolocation) {

src/server/browserType.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export abstract class BrowserType {
9292
slowMo: options.slowMo,
9393
persistent,
9494
headful: !options.headless,
95-
artifactsPath: options.artifactsPath,
9695
downloadsPath,
9796
browserProcess,
9897
proxy: options.proxy,
@@ -132,7 +131,7 @@ export abstract class BrowserType {
132131
}
133132
return dir;
134133
};
135-
// TODO: use artifactsPath for downloads.
134+
// TODO: add downloadsPath to newContext().
136135
const downloadsPath = await ensurePath(DOWNLOADS_FOLDER, options.downloadsPath);
137136

138137
if (!userDataDir) {

0 commit comments

Comments
 (0)