Using web-sys

Add web-sys as a dependency to your Cargo.toml

wasm-bindgen = "0.2"

version = "0.3"
features = [

Enable the cargo features for the APIs you're using

To keep build times super speedy, web-sys gates each Web interface behind a cargo feature. Find the type or method you want to use in the API documentation; it will list the features that must be enabled to access that API.

For example, if we're looking for the window.resizeTo function, we would search for resizeTo in the API documentation. We would find the web_sys::Window::resize_to function, which requires the Window feature. To get access to that function, we enable the Window feature in Cargo.toml:

version = "0.3"
features = [

Call the method!

# #![allow(unused_variables)]
#fn main() {
use wasm_bindgen::prelude::*;
use web_sys::Window;

pub fn make_the_window_small() {
    // Resize the window to 500px by 500px.
    let window = web_sys::window().unwrap();
    window.resize_to(500, 500)
        .expect("could not resize the window");