Skip to main content

Module cdp

Module cdp 

Source
Expand description

Chrome DevTools Protocol client.

Talks to a logged-in Chrome/Chromium exposing CDP (default http://127.0.0.1:9222) to do two things grabcli can’t do with HTTP alone:

  • export_cookies: read the browser’s Grab cookies (Storage.getCookies) so the user never pastes credentials.
  • mint_hydra: open a food.grab.com page in the browser, let it mint a real x-hydra-jwt, and sniff the header off the network events.
  • evaluate_in_origin: evaluate JS in a tab on a given origin (used to mint GrabMart reCAPTCHA v3 tokens on mart.grab.com).
  • Browser: drive one tab inside an isolated browser context (Target.createBrowserContext) for grab auth login; the context has its own cookies and outlives the process until disposed.

The endpoint is any CDP-speaking browser the user is logged into; grabcli doesn’t assume a particular one. It only drives a tab it opens or a tab already on food.grab.com, and never touches unrelated tabs.

Structs§

Browser
A browser-level CDP connection used to drive one page inside an isolated browser context (Target.createBrowserContext): its own cookie jar and storage, shared with no other tab, so nothing else in the browser can log it out and it can’t disturb the user’s tabs.
PageInfo
A page target as listed by /json (no websocket needed).

Functions§

default_context_cookies
The grab.com cookies of the browser’s default context (the user’s normal tabs): Storage.getCookies on the browser connection without a browserContextId. Values stay in memory; callers never print them.
evaluate_in_origin
Evaluate a JavaScript expression in a browser tab on origin (e.g. https://mart.grab.com) and return its JSON value. Promises are awaited.
export_cookies
Export Grab cookies from the browser into session, preserving any hydra token already present. Returns the browser User-Agent.
mint_hydra
Mint a hydra JWT by driving the browser: open/select a food.grab.com tab, navigate it to page, and sniff the x-hydra-jwt request header. Updates session.hydra_jwt, hydra_exp and web_app_version.
pages
All page targets of the browser, from GET /json. Read-only: nothing is attached to or changed.