fix(python): send a valid cookie regex filter from clear_cookies
Fixes #3270.
_cookie_filter always passed flags=flags or None, so a compiled pattern without i/m/s was serialized with exclude_unset=True as "flags": null. CookieRegex in the protocol schema declares flags as .optional(), which accepts a missing key but not null, so the RPC call was rejected and the cookie was never cleared — the plain string form worked, which is why this only hit compiled patterns.
- Leave
flagsunset when there is nothing to send. - Reject Python-only flags (
re.ASCII,re.LOCALE,re.VERBOSE,re.DEBUG) with a clearValueErrorinstead of dropping them silently and running a different pattern than the caller compiled.
Tests in packages/sdk-python/tests/test_browser_context.py:
test_browser_context_omits_unused_cookie_regex_flagsasserts the serialized filter has noflagskey.test_browser_context_rejects_unrepresentable_cookie_regex_flagscoversre.VERBOSE.
Summary by cubic
Fixes clear_cookies so compiled regex patterns without i/m/s flags no longer fail: the filter was serialized with "flags": null, which the protocol schema rejects, while plain string filters worked. The serialized filter now simply omits flags when there is no flag to send.
Also rejects Python-only regex flags (re.ASCII, re.LOCALE, re.VERBOSE, re.DEBUG) with a clear ValueError instead of silently dropping them and running a different pattern than the caller compiled.
Adds a changeset marking this fix as a patch for @browserbasehq/stagehand-python.