// Copyright (c) Microsoft Corporation. // Licensed under the MIT license. export type NetworkCookie = { name: string, value: string, domain: string, path: string, expires: number, size: number, httpOnly: boolean, secure: boolean, session: boolean, sameSite: 'Strict' | 'Lax' | 'None' }; export type SetNetworkCookieParam = { name: string, value: string, url?: string, domain?: string, path?: string, expires?: number, httpOnly?: boolean, secure?: boolean, sameSite?: 'Strict' | 'Lax' | 'None' }; export function filterCookies(cookies: NetworkCookie[], urls: string[]) { const parsedURLs = urls.map(s => new URL(s)); // Chromiums's cookies are missing sameSite when it is 'None' return cookies.filter(c => { if (!parsedURLs.length) return true; for (const parsedURL of parsedURLs) { if (parsedURL.hostname !== c.domain) continue; if (!parsedURL.pathname.startsWith(c.path)) continue; if ((parsedURL.protocol === 'https:') !== c.secure) continue; return true; } return false; }); }