fix: map Secure field in cookie conversions and add per-cookie error handling
The Secure field was dropped in both Playwright<->internal cookie conversion functions, causing cookies with __Secure-/__Host- prefixes to be rejected by Chromium. Additionally, batch AddCookies meant one invalid cookie would fail browser creation entirely. Changes: - Map Secure field in cookieToPlaywrightOptionalCookie and playwrightCookieToCookie - Add cookies one-by-one with slog.Warn on failure instead of failing the entire batch - Add unit tests for both conversion functions Closes #75 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -152,12 +152,11 @@ func initBrowser(opt BrowserOptions) (*browserInitResult, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting cookies from cookie jar: %w", err)
|
||||
}
|
||||
pwCookies := make([]playwright.OptionalCookie, len(cookies))
|
||||
for i, c := range cookies {
|
||||
pwCookies[i] = cookieToPlaywrightOptionalCookie(c)
|
||||
}
|
||||
if err := bctx.AddCookies(pwCookies); err != nil {
|
||||
return nil, fmt.Errorf("error adding cookies to browser: %w", err)
|
||||
for _, c := range cookies {
|
||||
oc := cookieToPlaywrightOptionalCookie(c)
|
||||
if err := bctx.AddCookies([]playwright.OptionalCookie{oc}); err != nil {
|
||||
slog.Warn("skipping invalid cookie", "name", c.Name, "host", c.Host, "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user