Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }

Implementations§

Source§

impl Session

Source

pub fn new(profile: impl Into<PathBuf>, mode: LaunchMode) -> Result<Self>

Source

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”.

Source

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.

Source

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.

Source

pub async fn with_page<T, F, Fut>(&self, f: F) -> Result<T>
where F: FnOnce(Page) -> Fut, Fut: Future<Output = Result<T>>,

The session’s own page, for callers that need to poke at the DOM.

Source

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.

Source

pub async fn close(&self) -> Result<()>

Source

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.

Source

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.

Source

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.

Source

pub async fn api( &self, method: &str, path: &str, body: Option<&Value>, ) -> Result<Value, ApiError>

Call a /kr-api/ endpoint from inside the page, retrying the two failures that are known to be recoverable.

Trait Implementations§

Source§

impl KrApi for Session

Source§

fn call<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, method: &'life1 str, path: &'life2 str, body: Option<&'life3 Value>, ) -> Pin<Box<dyn Future<Output = Result<Value, ApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Named call rather than api so it cannot be confused with, or silently shadowed by, Session::api.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,