fix(locale): document locale parameter (#990)

This commit is contained in:
Pavel Feldman 2020-02-13 13:37:59 -08:00 committed by GitHub
parent cb63021b2f
commit c15534ff01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 14 deletions

View file

@ -196,6 +196,7 @@ Indicates that the browser is connected.
- `latitude` <[number]> Latitude between -90 and 90. - `latitude` <[number]> Latitude between -90 and 90.
- `longitude` <[number]> Longitude between -180 and 180. - `longitude` <[number]> Longitude between -180 and 180.
- `accuracy` <[number]> Optional non-negative accuracy value. - `accuracy` <[number]> Optional non-negative accuracy value.
- `locale` <?[string]> Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules.
- `permissions` <[Object]> A map from origin keys to permissions values. See [browserContext.setPermissions](#browsercontextsetpermissionsorigin-permissions) for more details. - `permissions` <[Object]> A map from origin keys to permissions values. See [browserContext.setPermissions](#browsercontextsetpermissionsorigin-permissions) for more details.
- returns: <[Promise]<[BrowserContext]>> - returns: <[Promise]<[BrowserContext]>>
@ -228,6 +229,7 @@ Creates a new browser context. It won't share cookies/cache with other browser c
- `latitude` <[number]> Latitude between -90 and 90. - `latitude` <[number]> Latitude between -90 and 90.
- `longitude` <[number]> Longitude between -180 and 180. - `longitude` <[number]> Longitude between -180 and 180.
- `accuracy` <[number]> Optional non-negative accuracy value. - `accuracy` <[number]> Optional non-negative accuracy value.
- `locale` <?[string]> Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules.
- `permissions` <[Object]> A map from origin keys to permissions values. See [browserContext.setPermissions](#browsercontextsetpermissionsorigin-permissions) for more details. - `permissions` <[Object]> A map from origin keys to permissions values. See [browserContext.setPermissions](#browsercontextsetpermissionsorigin-permissions) for more details.
- returns: <[Promise]<[Page]>> - returns: <[Promise]<[Page]>>

View file

@ -44,7 +44,7 @@ export type BrowserContextOptions = {
javaScriptEnabled?: boolean, javaScriptEnabled?: boolean,
bypassCSP?: boolean, bypassCSP?: boolean,
userAgent?: string, userAgent?: string,
language?: string, locale?: string,
timezoneId?: string, timezoneId?: string,
geolocation?: types.Geolocation, geolocation?: types.Geolocation,
permissions?: { [key: string]: string[] }; permissions?: { [key: string]: string[] };

View file

@ -110,8 +110,8 @@ export class CRPage implements PageDelegate {
promises.push(this._updateViewport(true /* updateTouch */)); promises.push(this._updateViewport(true /* updateTouch */));
if (options.javaScriptEnabled === false) if (options.javaScriptEnabled === false)
promises.push(this._client.send('Emulation.setScriptExecutionDisabled', { value: true })); promises.push(this._client.send('Emulation.setScriptExecutionDisabled', { value: true }));
if (options.userAgent || options.language) if (options.userAgent || options.locale)
promises.push(this._client.send('Emulation.setUserAgentOverride', { userAgent: options.userAgent || '', acceptLanguage: options.language })); promises.push(this._client.send('Emulation.setUserAgentOverride', { userAgent: options.userAgent || '', acceptLanguage: options.locale }));
if (options.timezoneId) if (options.timezoneId)
promises.push(emulateTimezone(this._client, options.timezoneId)); promises.push(emulateTimezone(this._client, options.timezoneId));
if (options.geolocation) if (options.geolocation)

View file

@ -78,8 +78,8 @@ export class WKBrowser extends platform.EventEmitter implements Browser {
const context = this._createBrowserContext(browserContextId, options); const context = this._createBrowserContext(browserContextId, options);
if (options.ignoreHTTPSErrors) if (options.ignoreHTTPSErrors)
await this._browserSession.send('Browser.setIgnoreCertificateErrors', { browserContextId, ignore: true }); await this._browserSession.send('Browser.setIgnoreCertificateErrors', { browserContextId, ignore: true });
if (options.language) if (options.locale)
await this._browserSession.send('Browser.setLanguages', { browserContextId, languages: [options.language] }); await this._browserSession.send('Browser.setLanguages', { browserContextId, languages: [options.locale] });
await context._initialize(); await context._initialize();
this._contexts.set(browserContextId, context); this._contexts.set(browserContextId, context);
return context; return context;

View file

@ -142,10 +142,10 @@ export class WKPage implements PageDelegate {
} }
if (contextOptions.bypassCSP) if (contextOptions.bypassCSP)
promises.push(session.send('Page.setBypassCSP', { enabled: true })); promises.push(session.send('Page.setBypassCSP', { enabled: true }));
if (this._page._state.extraHTTPHeaders || contextOptions.language) { if (this._page._state.extraHTTPHeaders || contextOptions.locale) {
const headers = this._page._state.extraHTTPHeaders || {}; const headers = this._page._state.extraHTTPHeaders || {};
if (contextOptions.language) if (contextOptions.locale)
headers['Accept-Language'] = contextOptions.language; headers['Accept-Language'] = contextOptions.locale;
promises.push(session.send('Network.setExtraHTTPHeaders', { headers })); promises.push(session.send('Network.setExtraHTTPHeaders', { headers }));
} }
if (this._page._state.hasTouch) if (this._page._state.hasTouch)
@ -380,9 +380,9 @@ export class WKPage implements PageDelegate {
async setExtraHTTPHeaders(headers: network.Headers): Promise<void> { async setExtraHTTPHeaders(headers: network.Headers): Promise<void> {
const copy = { ...headers }; const copy = { ...headers };
const language = this._page.context()._options.language; const locale = this._page.context()._options.locale;
if (language) if (locale)
copy['Accept-Language'] = language; copy['Accept-Language'] = locale;
await this._updateState('Network.setExtraHTTPHeaders', { headers: copy }); await this._updateState('Network.setExtraHTTPHeaders', { headers: copy });
} }

View file

@ -225,7 +225,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
describe.skip(CHROMIUM || FFOX)('BrowserContext({language})', function() { describe.skip(CHROMIUM || FFOX)('BrowserContext({language})', function() {
it('should affect accept-language header', async({newPage, server}) => { it('should affect accept-language header', async({newPage, server}) => {
const page = await newPage({ language: 'fr-CH' }); const page = await newPage({ locale: 'fr-CH' });
const [request] = await Promise.all([ const [request] = await Promise.all([
server.waitForRequest('/empty.html'), server.waitForRequest('/empty.html'),
page.goto(server.EMPTY_PAGE), page.goto(server.EMPTY_PAGE),
@ -240,7 +240,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
expect(await page.evaluate(() => (1000000.50).toLocaleString())).toBe('1,000,000.5'); expect(await page.evaluate(() => (1000000.50).toLocaleString())).toBe('1,000,000.5');
} }
{ {
const page = await newPage({ language: 'fr-CH' }); const page = await newPage({ locale: 'fr-CH' });
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
expect(await page.evaluate(() => (1000000.50).toLocaleString())).toBe('1 000 000,5'); expect(await page.evaluate(() => (1000000.50).toLocaleString())).toBe('1 000 000,5');
} }
@ -253,7 +253,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
'Sat Nov 19 2016 10:12:34 GMT-0800 (PST)'); 'Sat Nov 19 2016 10:12:34 GMT-0800 (PST)');
} }
{ {
const page = await newPage({ language: 'de-de', timezoneId: 'Europe/Berlin' }); const page = await newPage({ locale: 'de-de', timezoneId: 'Europe/Berlin' });
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
expect(await page.evaluate(() => new Date(1479579154987).toString())).toBe( expect(await page.evaluate(() => new Date(1479579154987).toString())).toBe(
'Sat Nov 19 2016 19:12:34 GMT+0100 (Mitteleuropäische Normalzeit)'); 'Sat Nov 19 2016 19:12:34 GMT+0100 (Mitteleuropäische Normalzeit)');