kotlinx-browser icon indicating copy to clipboard operation
kotlinx-browser copied to clipboard

Impossible to call window.fetch without RequestInit

Open eymar opened this issue 2 months ago • 2 comments

With 0.5.0 version, some API (e.g. window.fetch, cache.match) do not allow option-less calls (when compiling to k/js).

Without kotlinx-browser it used to be possible to call just window.fetch(resPath). But now there is an error: [NO_VALUE_FOR_PARAMETER] No value passed for parameter 'init'.

Adding an empty init leads to another error.

val response = window.fetch(resPath, RequestInit())

CoroutineExceptionHandlerImpl.kt:7 TypeError: Failed to execute 'fetch' on 'Window': Failed to read the 'cache' property from 'RequestInit': The provided value 'null' is not a valid enum value of type RequestCache.

val response = window.fetch(resPath, RequestInit(cache = RequestCache.NO_CACHE))

TypeError: Failed to execute 'fetch' on 'Window': Failed to read the 'credentials' property from 'RequestInit': The provided value 'null' is not a valid enum value of type RequestCredentials.

And etc...

At the same time, k/wasm target compiles and works as usual.


Looks like it's related to https://github.com/Kotlin/kotlinx-browser/issues/17, but still here we have a different issue with k/js that a plain API call without init is not possible right now.

eymar avatar Oct 15 '25 12:10 eymar