Skip to content

Commit 5f74738

Browse files
authored
chore: revert api back to nullable video (#39933)
1 parent 9faf551 commit 5f74738

6 files changed

Lines changed: 14 additions & 5 deletions

File tree

docs/src/api/class-page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4455,7 +4455,7 @@ Optional handler function to route the request.
44554455

44564456
## method: Page.video
44574457
* since: v1.8
4458-
- returns: <[Video]>
4458+
- returns: <[null]|[Video]>
44594459

44604460
Video object associated with this page. Can be used to access the video file when using the `recordVideo` context option.
44614461

packages/playwright-client/types/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4800,7 +4800,7 @@ export interface Page {
48004800
* Video object associated with this page. Can be used to access the video file when using the `recordVideo` context
48014801
* option.
48024802
*/
4803-
video(): Video;
4803+
video(): null|Video;
48044804

48054805
viewportSize(): null|{
48064806
/**

packages/playwright-core/src/client/page.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,12 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
281281
this._timeoutSettings.setDefaultTimeout(timeout);
282282
}
283283

284-
video(): Video {
284+
video(): Video | null {
285+
// Note: we are creating Video object lazily, because we do not know
286+
// BrowserContextOptions when constructing the page - it is assigned
287+
// too late during launchPersistentContext.
288+
if (!this._browserContext._options.recordVideo)
289+
return null;
285290
return this._video;
286291
}
287292

packages/playwright-core/types/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4800,7 +4800,7 @@ export interface Page {
48004800
* Video object associated with this page. Can be used to access the video file when using the `recordVideo` context
48014801
* option.
48024802
*/
4803-
video(): Video;
4803+
video(): null|Video;
48044804

48054805
viewportSize(): null|{
48064806
/**

packages/playwright/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
404404
const preserveVideo = captureVideo && (videoMode === 'on' || (testFailed && videoMode === 'retain-on-failure') || (videoMode === 'on-first-retry' && testInfo.retry === 1));
405405
if (preserveVideo) {
406406
const { pagesWithVideo: pagesForVideo } = contexts.get(context)!;
407-
const videos = pagesForVideo.map(p => p.video());
407+
const videos = pagesForVideo.map(p => p.video()).filter(video => !!video);
408408
await Promise.all(videos.map(async v => {
409409
try {
410410
const savedPath = testInfo.outputPath(`video${counter ? '-' + counter : ''}.webm`);

tests/library/video.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ it.describe('screencast', () => {
164164
it.slow();
165165
it.skip(({ mode }) => mode !== 'default', 'video.path() is not available in remote mode');
166166

167+
it('should not have video by default', async ({ page }) => {
168+
expect(page.video()).toBeNull();
169+
});
170+
167171
it('videoSize should require videosPath', async ({ browser }) => {
168172
const error = await browser.newContext({ videoSize: { width: 100, height: 100 } }).catch(e => e);
169173
expect(error.message).toContain('"videoSize" option requires "videosPath" to be specified');

0 commit comments

Comments
 (0)