Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/playwright-core/src/server/bidi/bidiBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ export class BidiBrowserContext extends BrowserContext {
userContexts: [this._userContextId()],
}));
}
if (this._options.extraHTTPHeaders || this._options.locale)
promises.push(this.doUpdateExtraHTTPHeaders());
await Promise.all(promises);
}

Expand Down Expand Up @@ -320,6 +322,13 @@ export class BidiBrowserContext extends BrowserContext {
}

async doUpdateExtraHTTPHeaders(): Promise<void> {
let allHeaders = this._options.extraHTTPHeaders || [];
if (this._options.locale)
allHeaders = network.mergeHeaders([allHeaders, network.singleHeader('Accept-Language', this._options.locale)]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we set this custom header on the client end in both Firefox and WebKit in Playwright, but it feels like cutting corners a bit and I wonder if it'd make more sense to make it a part of the browser implementation of the emulation.setLocaleOverride command (similar how it is done in Chromium)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it'd make more sense to make it a part of the browser implementation of the emulation.setLocaleOverride command (similar how it is done in Chromium)?

That's the plan. I will remove this logic when the spec and Firefox' implementation have been updated.

await this._browser._browserSession.send('network.setExtraHeaders', {
headers: allHeaders.map(({ name, value }) => ({ name, value: { type: 'string', value } })),
userContexts: [this._userContextId()],
});
}

async setUserAgent(userAgent: string | undefined): Promise<void> {
Expand Down
11 changes: 11 additions & 0 deletions packages/playwright-core/src/server/bidi/bidiPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { BidiNetworkManager } from './bidiNetworkManager';
import { BidiPDF } from './bidiPdf';
import * as bidi from './third_party/bidiProtocol';

import * as network from '../network';
import type { RegisteredListener } from '../utils/eventsHelper';
import type * as accessibility from '../accessibility';
import type * as frames from '../frames';
Expand Down Expand Up @@ -297,6 +298,16 @@ export class BidiPage implements PageDelegate {
}

async updateExtraHTTPHeaders(): Promise<void> {
const locale = this._browserContext._options.locale;
const allHeaders = network.mergeHeaders([
this._browserContext._options.extraHTTPHeaders,
this._page.extraHTTPHeaders(),
locale ? network.singleHeader('Accept-Language', locale) : undefined,
]);
await this._session.send('network.setExtraHeaders', {
headers: allHeaders.map(({ name, value }) => ({ name, value: { type: 'string', value } })),
contexts: [this._session.sessionId],
});
}

async updateEmulateMedia(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ export interface Commands {
returnType: Bidi.Storage.SetCookieParameters;
};

'network.setExtraHeaders': {
params: Bidi.Network.SetExtraHeadersParameters;
returnType: Bidi.Network.SetExtraHeadersResult;
};
'network.addDataCollector': {
params: Bidi.Network.AddDataCollectorParameters;
returnType: Bidi.Network.AddDataCollectorResult;
Expand Down
Loading