Skip to content

Commit

Permalink
fix(extensions): do not enable screencast for background pages (#4919)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Jan 6, 2021
1 parent 8fd34c6 commit 0a2fe62
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/server/chromium/crPage.ts
Expand Up @@ -461,7 +461,7 @@ class FrameSession {
promises.push(this._evaluateOnNewDocument(source, 'main'));
for (const source of this._crPage._page._evaluateOnNewDocumentSources)
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 screencastId = createGuid();
const outputFile = path.join(this._crPage._browserContext._options.recordVideo.dir, screencastId + '.webm');
Expand Down
26 changes: 26 additions & 0 deletions test/chromium/launcher.spec.ts
Expand Up @@ -77,6 +77,32 @@ it('should return background pages', (test, { browserName }) => {
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 }) => {
test.skip(browserName !== 'chromium');
}, async ({browserType, browserOptions}) => {
Expand Down

0 comments on commit 0a2fe62

Please sign in to comment.