pub struct Worker { /* private fields */ }Expand description
A web/service/shared worker owned by a page.
Produced by Page::on_worker. The worker is
driven through its own CDP sub-session; call evaluate
to run JS in the worker’s execution context.
Implementations§
Source§impl Worker
impl Worker
Sourcepub fn on_close<F, Fut>(&self, handler: F)
pub fn on_close<F, Fut>(&self, handler: F)
Register a handler invoked once when the worker is destroyed.
A worker is reported as destroyed when the browser detaches its target
(Target.detachedFromTarget whose sessionId matches this worker’s
sub-session). That event is delivered on the parent session, so we
subscribe at the connection (browser/root) level and filter by session
id. We also watch the worker’s own session for
Runtime.executionContextDestroyed as a fallback. The handler fires at
most once: the first signal wins, the other is suppressed.
Sourcepub async fn evaluate<R: DeserializeOwned>(&self, expression: &str) -> Result<R>
pub async fn evaluate<R: DeserializeOwned>(&self, expression: &str) -> Result<R>
Evaluate a JS expression in the worker’s execution context, returning a typed result.
expression is wrapped as (() => { return (<expression>); })() and
the result’s value is parsed with serde.