Skip to content

Commit 0b7976a

Browse files
pavelfeldmanaslushnikov
authored andcommitted
fix(screencast): await for the first video frame on Chromium (#4145)
1 parent 2cd8604 commit 0b7976a

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

src/server/chromium/crPage.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,16 +757,19 @@ class FrameSession {
757757
const videoRecorder = await VideoRecorder.launch(options);
758758
this._screencastState = 'starting';
759759
try {
760-
await this._client.send('Page.startScreencast', {
761-
format: 'jpeg',
762-
quality: 90,
763-
maxWidth: options.width,
764-
maxHeight: options.height,
765-
});
766760
this._screencastState = 'started';
767761
this._videoRecorder = videoRecorder;
768762
this._screencastId = screencastId;
769763
this._crPage._browserContext._browser._videoStarted(this._crPage._browserContext, screencastId, options.outputFile, this._crPage.pageOrError());
764+
await Promise.all([
765+
this._client.send('Page.startScreencast', {
766+
format: 'jpeg',
767+
quality: 90,
768+
maxWidth: options.width,
769+
maxHeight: options.height,
770+
}),
771+
new Promise(f => this._client.once('Page.screencastFrame', f))
772+
]);
770773
} catch (e) {
771774
videoRecorder.stop().catch(() => {});
772775
throw e;

test/screencast.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,40 @@ describe('screencast', suite => {
196196
expect(fs.existsSync(path)).toBeTruthy();
197197
});
198198

199+
it('should expose video path blank page', async ({browser, testInfo}) => {
200+
const videosPath = testInfo.outputPath('');
201+
const size = { width: 320, height: 240 };
202+
const context = await browser.newContext({
203+
videosPath,
204+
viewport: size,
205+
videoSize: size
206+
});
207+
const page = await context.newPage();
208+
const path = await page.video()!.path();
209+
expect(path).toContain(videosPath);
210+
await context.close();
211+
expect(fs.existsSync(path)).toBeTruthy();
212+
});
213+
214+
it('should expose video path blank popup', async ({browser, testInfo}) => {
215+
const videosPath = testInfo.outputPath('');
216+
const size = { width: 320, height: 240 };
217+
const context = await browser.newContext({
218+
videosPath,
219+
viewport: size,
220+
videoSize: size
221+
});
222+
const page = await context.newPage();
223+
const [popup] = await Promise.all([
224+
page.waitForEvent('popup'),
225+
page.evaluate('window.open("about:blank")')
226+
]);
227+
const path = await popup.video()!.path();
228+
expect(path).toContain(videosPath);
229+
await context.close();
230+
expect(fs.existsSync(path)).toBeTruthy();
231+
});
232+
199233
it('should capture navigation', async ({browser, server, testInfo}) => {
200234
const videosPath = testInfo.outputPath('');
201235
const context = await browser.newContext({

0 commit comments

Comments
 (0)