feat(screencast): fire start evet for popups (#3600)

This commit is contained in:
Yury Semikhatsky 2020-08-24 17:23:54 -07:00 committed by GitHub
parent 22e2bf1227
commit b9d6324d14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 8 deletions

View File

@ -21,7 +21,6 @@ import { helper, RegisteredListener } from '../helper';
import { assert } from '../../utils/utils';
import * as network from '../network';
import { Page, PageBinding } from '../page';
import * as path from 'path';
import { ConnectionTransport } from '../transport';
import * as types from '../types';
import { Protocol } from './protocol';
@ -252,12 +251,6 @@ export class WKBrowserContext extends BrowserContext {
throw result;
if (result.isClosed())
throw new Error('Page has been closed.');
if (result._browserContext._screencastOptions) {
const contextOptions = result._browserContext._screencastOptions;
const outputFile = path.join(contextOptions.dir, helper.guid() + '.webm');
const options = Object.assign({}, contextOptions, {outputFile});
await wkPage.startScreencast(options);
}
return result;
}

View File

@ -25,6 +25,7 @@ import { WKExecutionContext } from './wkExecutionContext';
import { WKInterceptableRequest } from './wkInterceptableRequest';
import { WKWorkers } from './wkWorkers';
import { Page, PageDelegate, PageBinding } from '../page';
import * as path from 'path';
import { Protocol } from './protocol';
import * as dialog from '../dialog';
import { RawMouseImpl, RawKeyboardImpl } from './wkInput';
@ -114,6 +115,12 @@ export class WKPage implements PageDelegate {
for (const [key, value] of this._browserContext._permissions)
this._grantPermissions(key, value);
}
if (this._browserContext._screencastOptions) {
const contextOptions = this._browserContext._screencastOptions;
const outputFile = path.join(contextOptions.dir, helper.guid() + '.webm');
const options = Object.assign({}, contextOptions, {outputFile});
promises.push(this.startScreencast(options));
}
await Promise.all(promises);
}
@ -717,7 +724,7 @@ export class WKPage implements PageDelegate {
height: options.height,
scale: options.scale,
});
this._browserContext.emit(BrowserContext.Events.ScreencastStarted, new Screencast(options.outputFile, this._initializedPage!));
this._browserContext.emit(BrowserContext.Events.ScreencastStarted, new Screencast(options.outputFile, this._page));
} catch (e) {
this._recordingVideoFile = null;
throw e;

View File

@ -279,3 +279,26 @@ it.fail(options.CHROMIUM)('should fire start/stop events when page created/close
expect(stopEvent.page === newPage).toBe(true);
await context.close();
});
it.fail(options.CHROMIUM)('should fire start event for popups', async({browser, tmpDir, server, toImpl}) => {
if (!toImpl)
return;
// Use server side of the context. All the code below also uses server side APIs.
const context = toImpl(await browser.newContext());
await context._enableScreencast({width: 640, height: 480, dir: tmpDir});
expect(context._screencastOptions).toBeTruthy();
const page = await context.newPage();
await page.mainFrame().goto(server.EMPTY_PAGE);
const [startEvent, popup] = await Promise.all([
new Promise(resolve => context.on('screencaststarted', resolve)) as Promise<any>,
new Promise(resolve => context.on('page', resolve)) as Promise<any>,
page.mainFrame()._evaluateExpression(() => {
const win = window.open('about:blank');
win.close();
}, true)
]);
expect(startEvent.path).toBeTruthy();
expect(startEvent.page === popup).toBe(true);
await context.close();
});