-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
Hello, SB Community and Michael
My current goal is to get the cookie in browser, which has a "path" field. Which doesn't allow me to get that cookie if I'm not on the corresponding path (e.g. v2/auth) I've tried a lot of approaches, but redirecting to that path can't help me, because this exact cookie is deleted when I redirect to any page. (Important)
The only approach that can work is to enable CDP mode, (which I would like not to do, but it seems that there is no solutions).
I'm activating CDP In big application
async def registration_scenario(
api_key: str, service: str, user_id: int, is_male: bool = True
) -> str | Exception:
platform: str = get_platform()
user_agent: str = get_user_agent(platform)
window_size: str = get_window_size()
with SB(
uc=True,
browser="chrome",
locale="ru",
position="0,0",
agent=user_agent,
window_size=window_size,
proxy=proxy,
block_images=True,
) as driver:
manager = RegistrationManager(
driver, api_key, service, is_male, user_id, platform
)
result = await manager.execute_queue()
return result
And at some point to get that cookie I need to activate CDP mode, it will be called but from async function but if I call it, it says that there is already another event loop. Is there any solution to this problem? Or maybe you can suggest me a way how can I extract that cookie from chromium.
Also will it even work if I enable CDP mode while running the code, if activate_cdp_mode() opens a new instance of browser?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments
-
Also this cookie is not only in cookie for one time, it's also can be found in request headers.
Beta Was this translation helpful? Give feedback.
All reactions
-
The available cookie methods for CDP Mode are:
sb.cdp.get_all_cookies(*args, **kwargs) sb.cdp.set_all_cookies(*args, **kwargs) sb.cdp.save_cookies(*args, **kwargs) sb.cdp.load_cookies(*args, **kwargs) sb.cdp.clear_cookies() sb.cdp.get_cookie_string()
There's a CDP Mode cookie example here:
Do browser navigation after activating CDP Mode, as the URL changes on activation.
Beta Was this translation helpful? Give feedback.
All reactions
-
The best approach we found is to just
sb.execute_cdp_cmd('Storage.getCookies', cmd_args={})
Can get all the cookies, even the cookies which can be accessed only on specified path.
Doesn't need to enable CDP mode for using.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1