pub struct Session { /* private fields */ }Implementations§
Source§impl Session
impl Session
pub fn new(profile: impl Into<PathBuf>, mode: LaunchMode) -> Result<Self>
Sourcepub fn user_agent(&self) -> Result<&str>
pub fn user_agent(&self) -> Result<&str>
The User-Agent this session presents to Cloudflare.
Exposed because it is the single load-bearing fact here: a string
containing HeadlessChrome is blocked outright, one without it is served the
real shop. The spike prints it so a reader can see why the page loaded, and
so a regression in user_agent() shows up as evidence rather than as a bare
“Cloudflare blocked us”.
Sourcepub async fn set_build(&self, build: Option<String>)
pub async fn set_build(&self, build: Option<String>)
Seed or clear the cached X-K-Build-Number.
Normally it is learned automatically from any /kr-api/ response header.
This exists so the stale-build retry can be exercised deliberately (see
probe --build=<value>) rather than only on a cold start.
Sourcepub async fn open_extra_page(&self, url: &str) -> Result<Page>
pub async fn open_extra_page(&self, url: &str) -> Result<Page>
Open an additional tab that this Session does not manage.
login needs this. The session’s own page is where API calls run, and
ensure_live will navigate it back to the shop whenever it finds it on
another origin. Signing in goes via login.kesko.fi, a different origin –
so if the human were driving the session’s page, the poller would yank it
back to /kauppa every few seconds, mid-login. Give them their own tab.
Sourcepub async fn with_page<T, F, Fut>(&self, f: F) -> Result<T>
pub async fn with_page<T, F, Fut>(&self, f: F) -> Result<T>
The session’s own page, for callers that need to poke at the DOM.
Sourcepub fn signal_shutdown(&self)
pub fn signal_shutdown(&self)
Tear down the browser so Chrome flushes cookies into the profile.
Dropping it instead kills the process, and an unflushed profile is exactly how a login silently fails to persist. Ask every in-flight wait to give up, without awaiting anything.
Separate from Session::close because shutdown has to stop a login first, and
that await can itself be queued behind the live lock this flag releases.
pub async fn close(&self) -> Result<()>
Sourcepub async fn release_for_login(&self) -> Result<(), ApiError>
pub async fn release_for_login(&self) -> Result<(), ApiError>
Hand the profile over to an interactive login, and stop serving until it is done.
A profile directory supports exactly one Chrome (SingletonLock), so a headful
login browser cannot coexist with this session’s headless one. Rather than teach
serve to run headful, it lets go entirely: shut the browser down, refuse to
launch another, and let the login process own the profile meanwhile. The login
writes its cookies there, and the next tool call relaunches into them.
Sourcepub async fn resume_after_login(&self)
pub async fn resume_after_login(&self)
Start serving again after Session::release_for_login, whatever the outcome.
Deliberately does not relaunch: the browser comes back lazily on the next tool call, which is also when a fresh login would be picked up.
Sourcepub async fn close_if_idle(&self, timeout: Duration) -> Result<bool>
pub async fn close_if_idle(&self, timeout: Duration) -> Result<bool>
Close an idle browser generation without marking the session closed forever.
Returns true when a live browser was shut down.