diff --git a/docs/src/api/params.md b/docs/src/api/params.md index 47d79018f0..1585aa2cf9 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -207,17 +207,16 @@ Specify environment variables that will be visible to the browser. Defaults to ` ## js-python-context-option-storage-state * langs: js, python - `storageState` <[path]|[Object]> - - `cookies` <[Array]<[Object]>> Optional cookies to set for context + - `cookies` <[Array]<[Object]>> cookies to set for context - `name` <[string]> - `value` <[string]> - - `url` <[string]> Optional either url or domain / path are required - - `domain` <[string]> Optional either url or domain / path are required - - `path` <[string]> Optional either url or domain / path are required - - `expires` <[float]> Optional Unix time in seconds. - - `httpOnly` <[boolean]> Optional httpOnly flag - - `secure` <[boolean]> Optional secure flag - - `sameSite` <[SameSiteAttribute]<"Strict"|"Lax"|"None">> Optional sameSite flag - - `origins` <[Array]<[Object]>> Optional localStorage to set for context + - `domain` <[string]> domain and path are required + - `path` <[string]> domain and path are required + - `expires` <[float]> Unix time in seconds. + - `httpOnly` <[boolean]> + - `secure` <[boolean]> + - `sameSite` <[SameSiteAttribute]<"Strict"|"Lax"|"None">> sameSite flag + - `origins` <[Array]<[Object]>> localStorage to set for context - `origin` <[string]> - `localStorage` <[Array]<[Object]>> - `name` <[string]> diff --git a/tests/browsercontext-storage-state.spec.ts b/tests/browsercontext-storage-state.spec.ts index 4c0e76e3fb..ad28be2d85 100644 --- a/tests/browsercontext-storage-state.spec.ts +++ b/tests/browsercontext-storage-state.spec.ts @@ -51,6 +51,7 @@ it('should capture local storage', async ({ contextFactory }) => { it('should set local storage', async ({ browser }) => { const context = await browser.newContext({ storageState: { + cookies: [], origins: [ { origin: 'https://www.example.com', diff --git a/tests/global-fetch.spec.ts b/tests/global-fetch.spec.ts index 2ec950e300..6df9c61e43 100644 --- a/tests/global-fetch.spec.ts +++ b/tests/global-fetch.spec.ts @@ -152,3 +152,9 @@ it('should set playwright as user-agent', async ({ playwright, server }) => { ]); expect(serverRequest.headers['user-agent']).toBe('Playwright/' + getPlaywrightVersion()); }); + +it('should be able to construct with context options', async ({ playwright, server, contextOptions }) => { + const request = await playwright.request.newContext(contextOptions); + const response = await request.get(server.EMPTY_PAGE); + expect(response.ok()).toBeTruthy(); +}); diff --git a/types/types.d.ts b/types/types.d.ts index 116e50e777..dfb18256a6 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -12367,53 +12367,42 @@ export interface Browser extends EventEmitter { */ storageState?: string|{ /** - * Optional cookies to set for context + * cookies to set for context */ - cookies?: Array<{ + cookies: Array<{ name: string; value: string; /** - * Optional either url or domain / path are required + * domain and path are required */ - url?: string; + domain: string; /** - * Optional either url or domain / path are required + * domain and path are required */ - domain?: string; + path: string; /** - * Optional either url or domain / path are required + * Unix time in seconds. */ - path?: string; + expires: number; + + httpOnly: boolean; + + secure: boolean; /** - * Optional Unix time in seconds. + * sameSite flag */ - expires?: number; - - /** - * Optional httpOnly flag - */ - httpOnly?: boolean; - - /** - * Optional secure flag - */ - secure?: boolean; - - /** - * Optional sameSite flag - */ - sameSite?: "Strict"|"Lax"|"None"; + sameSite: "Strict"|"Lax"|"None"; }>; /** - * Optional localStorage to set for context + * localStorage to set for context */ - origins?: Array<{ + origins: Array<{ origin: string; localStorage: Array<{ @@ -14680,53 +14669,42 @@ export interface BrowserContextOptions { */ storageState?: string|{ /** - * Optional cookies to set for context + * cookies to set for context */ - cookies?: Array<{ + cookies: Array<{ name: string; value: string; /** - * Optional either url or domain / path are required + * domain and path are required */ - url?: string; + domain: string; /** - * Optional either url or domain / path are required + * domain and path are required */ - domain?: string; + path: string; /** - * Optional either url or domain / path are required + * Unix time in seconds. */ - path?: string; + expires: number; + + httpOnly: boolean; + + secure: boolean; /** - * Optional Unix time in seconds. + * sameSite flag */ - expires?: number; - - /** - * Optional httpOnly flag - */ - httpOnly?: boolean; - - /** - * Optional secure flag - */ - secure?: boolean; - - /** - * Optional sameSite flag - */ - sameSite?: "Strict"|"Lax"|"None"; + sameSite: "Strict"|"Lax"|"None"; }>; /** - * Optional localStorage to set for context + * localStorage to set for context */ - origins?: Array<{ + origins: Array<{ origin: string; localStorage: Array<{