Skip to content

Commit 0e1076b

Browse files
authored
Merge pull request #119 from parthlambdatest/Dot_3790
add validation for cookies
2 parents 6107e48 + 1a6df66 commit 0e1076b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/lib/processSnapshot.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,27 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
9696
// Setting the cookies in playwright context
9797
const domainName = new URL(snapshot.url).hostname;
9898
ctx.log.debug('Setting cookies in context for domain:', domainName);
99+
100+
99101
const cookieArray = snapshot.dom.cookies.split('; ').map(cookie => {
102+
if (!cookie) return null;
100103
const [name, value] = cookie.split('=');
104+
if (!name || !value) return null;
105+
101106
return {
102107
name: name.trim(),
103108
value: value.trim(),
104109
domain: domainName,
105110
path: '/'
106111
};
107-
});
108-
await context.addCookies(cookieArray);
112+
}).filter(Boolean);
113+
114+
115+
if (cookieArray && Array.isArray(cookieArray) && cookieArray.length > 0) {
116+
await context.addCookies(cookieArray);
117+
} else {
118+
ctx.log.debug('No valid cookies to add.');
119+
}
109120

110121
const page = await context.newPage();
111122
let cache: Record<string, any> = {};

0 commit comments

Comments
 (0)