fix(har): HAR artifacts need to be marked remote (#8462)

This is a follow-up fix to microsoft/playwright#8385.

Testing options are limited right now, but this change was confirmed
with a client running on my physical machine and a LaunchServer running
in a Docker container.

Before this change, the har.spec.ts only passed when the client and
server were on the some filesystem.

microsoft/playwright#8450 will likely give us options to test this in an
automated way in the official CI suite.
This commit is contained in:
Ross Wollman 2021-08-26 11:26:08 -07:00 committed by GitHub
parent 17146b44c2
commit a1313727e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -35,6 +35,7 @@ import * as structs from '../../types/structs';
import { CDPSession } from './cdpSession';
import { Tracing } from './tracing';
import type { BrowserType } from './browserType';
import { Artifact } from './artifact';
export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel, channels.BrowserContextInitializer> implements api.BrowserContext {
_pages = new Set<Page>();
@ -346,7 +347,11 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel,
await this._browserType?._onWillCloseContext?.(this);
if (this._options.recordHar) {
const har = await this._channel.harExport();
await har.artifact.saveAs({ path: this._options.recordHar.path });
const artifact = Artifact.from(har.artifact);
if (this.browser()?._remoteType)
artifact._isRemote = true;
await artifact.saveAs(this._options.recordHar.path);
await artifact.delete();
}
await channel.close();
await this._closedPromise;

View File

@ -454,3 +454,24 @@ test('should be able to connect when the wsEndpont is passed as the first argume
expect(await page.evaluate('1 + 2')).toBe(3);
await browser.close();
});
test('should save har', async ({browserType, startRemoteServer, server}, testInfo) => {
const remoteServer = await startRemoteServer();
const browser = await browserType.connect(remoteServer.wsEndpoint());
const harPath = testInfo.outputPath('test.har');
const context = await browser.newContext({
recordHar: {
path: harPath,
}
});
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
await context.close();
await browser.close();
const log = JSON.parse(fs.readFileSync(harPath).toString())['log'];
expect(log.entries.length).toBe(1);
const entry = log.entries[0];
expect(entry.pageref).toBe(log.pages[0].id);
expect(entry.request.url).toBe(server.EMPTY_PAGE);
});