fix(cookies): follow up to make all platform tests pass

This commit is contained in:
Pavel Feldman 2019-12-02 16:48:38 -08:00
parent 0ffd99bdac
commit 8989da6c16
3 changed files with 10 additions and 4 deletions

View File

@ -69,8 +69,9 @@ export class BrowserContext extends EventEmitter {
async cookies(...urls: string[]): Promise<NetworkCookie[]> {
const { cookies } = await this._browser._client.send('Storage.getCookies', { browserContextId: this._id || undefined });
return filterCookies(cookies.map(c => {
const copy = { sameSite: 'None', ...c, size: undefined } as NetworkCookie;
return copy;
const copy: any = { sameSite: 'None', ...c };
delete copy.size;
return copy as NetworkCookie;
}), urls);
}

View File

@ -294,7 +294,11 @@ export class BrowserContext extends EventEmitter {
const { cookies } = await this._connection.send('Browser.getCookies', {
browserContextId: this._browserContextId || undefined
});
return filterCookies(cookies, urls);
return filterCookies(cookies, urls).map(c => {
const copy: any = { ... c };
delete copy.size;
return copy as NetworkCookie;
});
}
async clearCookies() {

View File

@ -3,6 +3,7 @@
import * as frames from './frames';
import { assert } from './helper';
import { NetworkManager } from './chromium/NetworkManager';
export type NetworkCookie = {
name: string,
@ -28,7 +29,7 @@ export type SetNetworkCookieParam = {
sameSite?: 'Strict' | 'Lax' | 'None'
};
export function filterCookies(cookies: NetworkCookie[], urls: string[]) {
export function filterCookies(cookies: NetworkCookie[], urls: string[]): NetworkCookie[] {
const parsedURLs = urls.map(s => new URL(s));
// Chromiums's cookies are missing sameSite when it is 'None'
return cookies.filter(c => {