fix(extensions): do not enable screencast for background pages (#4919)

This commit is contained in:
Yury Semikhatsky 2021-01-06 15:08:28 -08:00 committed by GitHub
parent 8fd34c6beb
commit 0a2fe62cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -461,7 +461,7 @@ class FrameSession {
promises.push(this._evaluateOnNewDocument(source, 'main')); promises.push(this._evaluateOnNewDocument(source, 'main'));
for (const source of this._crPage._page._evaluateOnNewDocumentSources) for (const source of this._crPage._page._evaluateOnNewDocumentSources)
promises.push(this._evaluateOnNewDocument(source, 'main')); promises.push(this._evaluateOnNewDocument(source, 'main'));
if (this._isMainFrame() && this._crPage._browserContext._options.recordVideo) { if (this._isMainFrame() && this._crPage._browserContext._options.recordVideo && hasUIWindow) {
const size = this._crPage._browserContext._options.recordVideo.size || this._crPage._browserContext._options.viewport || { width: 1280, height: 720 }; const size = this._crPage._browserContext._options.recordVideo.size || this._crPage._browserContext._options.viewport || { width: 1280, height: 720 };
const screencastId = createGuid(); const screencastId = createGuid();
const outputFile = path.join(this._crPage._browserContext._options.recordVideo.dir, screencastId + '.webm'); const outputFile = path.join(this._crPage._browserContext._options.recordVideo.dir, screencastId + '.webm');

View File

@ -77,6 +77,32 @@ it('should return background pages', (test, { browserName }) => {
await context.close(); await context.close();
}); });
it('should return background pages when recording video', (test, { browserName }) => {
test.skip(browserName !== 'chromium');
}, async ({browserType, testInfo, browserOptions, createUserDataDir}) => {
const userDataDir = await createUserDataDir();
const extensionPath = path.join(__dirname, '..', 'assets', 'simple-extension');
const extensionOptions = {...browserOptions,
headless: false,
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`,
],
recordVideo: {
dir: testInfo.outputPath(''),
},
};
const context = await browserType.launchPersistentContext(userDataDir, extensionOptions) as ChromiumBrowserContext;
const backgroundPages = context.backgroundPages();
const backgroundPage = backgroundPages.length
? backgroundPages[0]
: await context.waitForEvent('backgroundpage');
expect(backgroundPage).toBeTruthy();
expect(context.backgroundPages()).toContain(backgroundPage);
expect(context.pages()).not.toContain(backgroundPage);
await context.close();
});
it('should not create pages automatically', (test, { browserName }) => { it('should not create pages automatically', (test, { browserName }) => {
test.skip(browserName !== 'chromium'); test.skip(browserName !== 'chromium');
}, async ({browserType, browserOptions}) => { }, async ({browserType, browserOptions}) => {