http-rs / http-rs/surf

TypeError: 'clearTimeout' called on an object that does not implement interface Window

Open
#338 1 comment 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
Rust
Stars
1.5k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

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 -
1. Is it because I am using unwrap() on the surf request ?
2. When await.unwrap() change to await? , following errors comes in wasm-pack build
"surf::error does not implement for wasm_bindgen::Jsvalue"

```
#[wasm_bindgen]
pub async fn run() -> Result{


let url = format!("https://api.github.com/repos/{}/branches/master","rustwasm/wasm-bindgen");
web_sys::console::log_1(&url.clone().into()) ;
web_sys::console::log_1(&"build surf request call".into()) ;
let mut res = surf::
get(url)
.header("accept","application/vnd.github.v3+json")
.send()
.await.unwrap();

web_sys::console::log_1(&"finished surf request call".into()) ;
let text = res.body_string().await.unwrap();
// web_sys::console::log_1(&res.toclone().into()) ;
let branch_json: Branch = serde_json::from_str(&text).unwrap();
Ok(JsValue::from_serde(&branch_json).unwrap())
}

```
Error screenshot from browser
```
Source map error: Error: NetworkError when attempting to fetch resource.
Resource URL: webpack:///./node_modules/sockjs-client/dist/sockjs.js?
Source Map URL: sockjs.js.map
https://api.github.com/repos/rustwasm/wasm-bindgen/branches/master wasmexp_bg.js:373:13
build surf request call wasmexp_bg.js:373:13
Uncaught (in promise) TypeError: 'clearTimeout' called on an object that does not implement interface Window.
__wbg_clearTimeout_d8b36ad8fa330187 http://localhost:8080/bootstrap.js:83
__wbg_adapter_29 webpack:///../pkg/wasmexp_bg.js?:272
real webpack:///../pkg/wasmexp_bg.js?:253
promise callback*__wbg_then_a6860c82b90816ca webpack:///../pkg/wasmexp_bg.js?:510
__wbg_then_a6860c82b90816ca http://localhost:8080/bootstrap.js:173
__wbg_adapter_29 webpack:///../pkg/wasmexp_bg.js?:272
real webpack:///../pkg/wasmexp_bg.js?:253
bootstrap.js:83:72
```
[](https://imgur.com/dTIUWK1)

Contributor guide

Open the contributing guide

Research direction

Reproduce the wasm-pack build and browser request using the issue's Rust snippet, then inspect bootstrap.js and the generated wasmexp_bg.js around the clearTimeout bridge. Determine why the surf request fails in the WASM environment and whether the reported error conversion also blocks the build; done means the request completes without the browser TypeError and the example builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
networking, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.