mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
![]() |
// 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;
|
||
|
});
|
||
|
}
|