File tree 2 files changed +20
-4
lines changed
2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -311,7 +311,7 @@ def _on_download(self, params: Any) -> None:
311
311
312
312
def _on_video (self , params : Any ) -> None :
313
313
artifact = from_channel (params ["artifact" ])
314
- cast ( Video , self .video )._artifact_ready (artifact )
314
+ self ._force_video ( )._artifact_ready (artifact )
315
315
316
316
@property
317
317
def context (self ) -> "BrowserContext" :
@@ -1064,13 +1064,21 @@ async def pdf(
1064
1064
await async_writefile (path , decoded_binary )
1065
1065
return decoded_binary
1066
1066
1067
+ def _force_video (self ) -> Video :
1068
+ if not self ._video :
1069
+ self ._video = Video (self )
1070
+ return self ._video
1071
+
1067
1072
@property
1068
1073
def video (
1069
1074
self ,
1070
1075
) -> Optional [Video ]:
1071
- if not self ._video :
1072
- self ._video = Video (self )
1073
- return self ._video
1076
+ # Note: we are creating Video object lazily, because we do not know
1077
+ # BrowserContextOptions when constructing the page - it is assigned
1078
+ # too late during launchPersistentContext.
1079
+ if not self ._browser_context ._options .get ("recordVideo" ):
1080
+ return None
1081
+ return self ._force_video ()
1074
1082
1075
1083
def _close_error_with_reason (self ) -> TargetClosedError :
1076
1084
return TargetClosedError (
Original file line number Diff line number Diff line change @@ -76,3 +76,11 @@ async def test_should_not_error_if_page_not_closed_before_save_as(
76
76
await saved
77
77
await page .context .close ()
78
78
assert os .path .exists (out_path )
79
+
80
+
81
+ async def test_should_be_None_if_not_recording (
82
+ browser : Browser , tmpdir : Path , server : Server
83
+ ) -> None :
84
+ page = await browser .new_page ()
85
+ assert page .video is None
86
+ await page .close ()
You can’t perform that action at this time.
0 commit comments