How to call navigator.credentials.get/create from Yew #1699
-
Hi there, I was interested to call navigator.credentials.get/create from a yew applications. Generally I think this seems like the ability for yew to call out to a javascript function or object that already exists in the context, but I'm not 100% clear on how to achieve this. While there are a lot of examples and docs, none of them seem to show this behaviour. Even as a simple example is it possible to say ... call console.log() from within yew (without ConsoleServices) for example? How would you call something in javascript from Yew? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi!
Calling |
Beta Was this translation helpful? Give feedback.
Hi!
Yew needs to sit on top of a set of bindings to in-browser Javascript APIs. Currently, there are two options – web-sys and stdweb (but support for stdweb is being deprecated because stdweb is no longer actively maintained).
To call Javascript functions you should use
web-sys
(a set of bindings to Javascript API's maintained by the rust-wasm working group). For navigator.credentials.get for example you would roughly want:Navigator
from https://docs.rs/web-sys/0.3.46/web_sys/struct.Window.html#method.navigatorcredentials
method on this instance (https://docs.rs/web-sys/0.3.46/web_sys/struct.Navigator.html#method.credentials)get
. …