pub struct JsHandle { /* private fields */ }Expand description
A handle for running JavaScript in a web view. Copy, like Trigger, so it can be captured by
several closures. Bind it with WebView::js; evaluating before the view is realized fails
with EvalError::ViewGone.
Implementations§
Source§impl JsHandle
impl JsHandle
Sourcepub fn renderer(&self) -> WebRenderer
pub fn renderer(&self) -> WebRenderer
Engine currently attached to this handle.
pub fn new() -> Self
Sourcepub async fn snapshot(&self, max_width_px: u32) -> Result<Vec<u8>, EvalError>
pub async fn snapshot(&self, max_width_px: u32) -> Result<Vec<u8>, EvalError>
Capture the visible page as PNG bytes, at most max_width_px physical pixels wide (the
height follows the view’s aspect ratio). Meant for thumbnails such as a tab overview.
The capture is the engine’s own rendering of what the view shows, not a re-render of the
document. A view that is not on screen (a background tab) may capture blank or fail with
EvalError::Threw, depending on the engine. Engines without a capture API (ArkWeb,
web-dom’s iframe) fail with EvalError::Unsupported; see docs/webview.md.
§Errors
Returns EvalError::Unsupported on an engine without a capture API, EvalError::Threw
when the engine cannot capture the view, and EvalError::Engine when its reply is not PNG
data.
Read URL, title, loading status and actual native history availability. Emulated iframe hosts return Unsupported rather than guessing browser history.
§Errors
Returns EvalError::Unsupported on an emulated iframe host, or the error of the request
to the backend.
Read cookies (including HttpOnly) eligible for this URL from the bound view’s profile.
Treat the returned header as a credential; never log it or send it to a different origin.
§Errors
Returns EvalError::Unsupported when url is not an HTTP or HTTPS URL or the backend
cannot read cookies, or the error of the request to the backend.
Store an HTTP Set-Cookie response in the browser’s own jar.
Sourcepub fn clear_data(&self) -> EvalFuture ⓘ
pub fn clear_data(&self) -> EvalFuture ⓘ
Clear all browser data in this profile. Use a dedicated site profile to forget one site. Await completion before reusing its cookies or allowing another request to that site.
Sourcepub fn eval(&self, script: impl AsRef<str>) -> EvalFuture ⓘ
pub fn eval(&self, script: impl AsRef<str>) -> EvalFuture ⓘ
Evaluate script and resolve with its result as JSON text.
Nothing is dispatched until the future is polled. Dropping it deregisters the request, so a late reply is discarded, but the script keeps running: no backend can cancel one.
Trait Implementations§
Auto Trait Implementations§
impl !Send for JsHandle
impl !Sync for JsHandle
impl Forget for JsHandle
impl Freeze for JsHandle
impl Move for JsHandle
impl RefUnwindSafe for JsHandle
impl Unpin for JsHandle
impl UnsafeUnpin for JsHandle
impl UnwindSafe for JsHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more