Open davnav opened 2 years ago
@davnav, @Fishrock123 I've recently come across this error too, and although I'm not certain it is exactly the same error, I'm pretty sure it is. The error message is different depending on the browser.
When using Surf inside WASM, which is then bundled by Webpack, the wasm-bindgen-futures
crate (which is used by async_std
in WASM) is trying to call clearTimeout on the future, but the global object in Webpack is not window, and therefore the function fails. I'm not sure if this is an error in the wasm-bindgen-futures
crate, or if it can be handled differently within surf
/ http-client
.
There was a similar issue in the rustwasm/gloo project which solved the problem by ensuring that clearTimeout
was called on the window object specifically, and not on the global context (which isn't always Window, due to Webpack).
The line in question which causes this error (I think) is:
async_std::future::timeout(timeout, conn).await??
One way of getting around this error temporarily is to disable timeouts...
use surf::Client;
use surf::Config;
let client: Client = Config::new().set_timeout(None).try_into().unwrap();
let mut req = cli.get("https://google.com");
let mut res = req.send().await?;
// This now doesn't cause an error
I've looked into trying to ensure that the module context in Webpack is window
, but I haven't worked out a way of doing this yet...
When try to run request for wasm through surf ( code snippet below) and I am getting "clearTimeout' called on an object that does not implement interface Window" I suspect following could be the issue -
Error screenshot from browser