2021-01-18 06:09:40 +01:00
|
|
|
---
|
|
|
|
|
id: videos
|
|
|
|
|
title: "Videos"
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
<!-- TOC -->
|
|
|
|
|
|
|
|
|
|
Playwright can record videos for all pages in a [browser context](./core-concepts.md#browser-contexts). Videos are saved
|
|
|
|
|
upon context closure, so make sure to await [`method: BrowserContext.close`].
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
const context = await browser.newContext({ recordVideo: { dir: 'videos/' } });
|
|
|
|
|
// Make sure to await close, so that videos are saved.
|
|
|
|
|
await context.close();
|
2021-03-02 05:14:19 +01:00
|
|
|
```
|
2021-01-18 06:09:40 +01:00
|
|
|
|
2021-03-02 05:14:19 +01:00
|
|
|
```java
|
2021-03-05 22:50:34 +01:00
|
|
|
context = browser.newContext(new Browser.NewContextOptions().setRecordVideoDir(Paths.get("videos/")));
|
2021-03-02 05:14:19 +01:00
|
|
|
// Make sure to close, so that videos are saved.
|
|
|
|
|
context.close();
|
|
|
|
|
```
|
2021-01-18 06:09:40 +01:00
|
|
|
|
2021-03-02 05:14:19 +01:00
|
|
|
```python async
|
|
|
|
|
context = await browser.new_context(record_video_dir="videos/")
|
|
|
|
|
# Make sure to await close, so that videos are saved.
|
|
|
|
|
await context.close()
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
|
context = browser.new_context(record_video_dir="videos/")
|
|
|
|
|
# Make sure to close, so that videos are saved.
|
|
|
|
|
context.close()
|
|
|
|
|
```
|
|
|
|
|
|
2021-05-15 20:37:21 +02:00
|
|
|
```csharp
|
|
|
|
|
var context = await browser.NewContextAsync(recordVideoDir: "videos/");
|
|
|
|
|
// Make sure to close, so that videos are saved.
|
|
|
|
|
await context.CloseAsync();
|
|
|
|
|
```
|
|
|
|
|
|
2021-03-02 05:14:19 +01:00
|
|
|
You can also specify video size, it defaults to viewport size scaled down to fit 800x800.
|
|
|
|
|
|
|
|
|
|
```js
|
2021-01-18 06:09:40 +01:00
|
|
|
const context = await browser.newContext({
|
|
|
|
|
recordVideo: {
|
|
|
|
|
dir: 'videos/',
|
2021-05-15 20:37:21 +02:00
|
|
|
size: { width: 640, height: 480 },
|
2021-01-18 06:09:40 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
```
|
|
|
|
|
|
2021-03-01 18:18:44 +01:00
|
|
|
```java
|
|
|
|
|
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
2021-03-05 22:50:34 +01:00
|
|
|
.setRecordVideoDir(Paths.get("videos/"))
|
2021-05-15 20:37:21 +02:00
|
|
|
.setRecordVideoSize(640, 480));
|
2021-03-01 18:18:44 +01:00
|
|
|
```
|
|
|
|
|
|
2021-01-18 06:09:40 +01:00
|
|
|
```python async
|
|
|
|
|
context = await browser.new_context(
|
|
|
|
|
record_video_dir="videos/",
|
2021-05-15 20:37:21 +02:00
|
|
|
record_video_size={"width": 640, "height": 480}
|
2021-01-18 06:09:40 +01:00
|
|
|
)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
|
context = browser.new_context(
|
|
|
|
|
record_video_dir="videos/",
|
2021-05-15 20:37:21 +02:00
|
|
|
record_video_size={"width": 640, "height": 480}
|
2021-01-18 06:09:40 +01:00
|
|
|
)
|
|
|
|
|
```
|
|
|
|
|
|
2021-05-15 20:37:21 +02:00
|
|
|
```csharp
|
|
|
|
|
var context = await browser.NewContextAsync(
|
|
|
|
|
recordVideoDir: "videos/",
|
|
|
|
|
recordVideoSize: new RecordVideoSize() { Width = 640, Height = 480 }
|
|
|
|
|
);
|
|
|
|
|
// Make sure to close, so that videos are saved.
|
|
|
|
|
await context.CloseAsync();
|
|
|
|
|
```
|
|
|
|
|
|
2021-03-02 05:14:19 +01:00
|
|
|
Saved video files will appear in the specified folder. They all have generated unique names.
|
|
|
|
|
For the multi-page scenarios, you can access the video file associated with the page via the
|
|
|
|
|
[`method: Page.video`].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
const path = await page.video().path();
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
|
path = page.video().path();
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```python async
|
|
|
|
|
path = await page.video.path()
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
|
path = page.video.path()
|
|
|
|
|
```
|
|
|
|
|
|
2021-05-15 20:37:21 +02:00
|
|
|
```csharp
|
|
|
|
|
var path = await page.Video.PathAsync();
|
|
|
|
|
```
|
|
|
|
|
|
2021-03-02 05:14:19 +01:00
|
|
|
:::note
|
|
|
|
|
Note that the video is only available after the page or browser context is closed.
|
|
|
|
|
:::
|
|
|
|
|
|
2021-01-18 06:09:40 +01:00
|
|
|
### API reference
|
|
|
|
|
- [BrowserContext]
|
|
|
|
|
- [`method: Browser.newContext`]
|
|
|
|
|
- [`method: Browser.newPage`]
|
|
|
|
|
- [`method: BrowserContext.close`]
|