Reputation: 1401
I am attempting to read a cookie from Wasm but have not found any examples so I guessed, but I guessed wrong.
c := js.Global().Get("Cookie").Get("cookiename")
fmt.Println(c)
This gives me an error:
panic: syscall/js: call of Value.Get on undefined
Given that I have not found any documentation regarding reading cookies from Wasm. Is this even possible?
Upvotes: 0
Views: 1334
Reputation: 21035
There are three issues here:
cookie
, not Cookie
To get the cookie string, use the following:
cookies := js.Global().Get("document").Get("cookie").String()
You will then need to process the string to iterate through the cookies and extract the one with the desired name. See Get cookie by name
As always with wasm, figure out the javascript code first then convert it to wasm.
Upvotes: 2