1use wasm_bindgen::JsCast;
3use web_sys::{Document, Element, Window};
4
5pub fn window() -> Window {
7 web_sys::window().unwrap()
8}
9
10pub fn document() -> Document {
12 web_sys::window().unwrap().document().unwrap()
13}
14
15pub fn body() -> std::result::Result<Element, String> {
17 let b = document()
18 .query_selector("body")
19 .unwrap()
20 .ok_or_else(|| "Unable to get body element".to_string())?;
21 Ok(b)
22}
23
24pub fn location() -> Result<web_sys::Location, wasm_bindgen::JsValue> {
25 let location = js_sys::Reflect::get(&js_sys::global(), &"location".into())?;
26 location.dyn_into()
27}