Go version
go version go1.22.5 linux/amd64
Output of go env
in your module/workspace:
GOOS="js"
GOARCH="wasm"
(the rest is not related, obviously)
What did you do?
The js.Value
that is used behind the scenes does not allow to remove previous event listeners, because the method requires a reference to the callback function
which isn't possible in go's syscall/js.Value
implementation.
The internal .ref
property seems to be lost along the way, no matter which way you want to call the removeEventListener
method. Even when using a wrapper object with a handleEvent()
method, the reference to that object (instance) seems to get lost, too.
As there's no way to use Call("removeEventListener", *js.Value)
I think this is an implementation bug that's incompatible with the removeEventListener API of Web Browsers.
What did you see happen?
The reduced test case, which shows a clickable element which should not be clickable after a second:
https://github.com/cookiengineer/golang-issue-68865
In the reduced test case, the removeEventListener() method call silently fails, and actually doesn't do anything, because I'm assuming that the method gets called outside the WebASM context with the wrong reference (and a new wrapped object/value).
What did you expect to see?
As I think this is an implementation bug, I'm assuming that the syscall/js.Value.Call()
method at some point should accept *js.Value
as function parameters and be able to use those outside the WebASM context in the Web Browser's sandbox.
But I don't know much about the internals other than what I was able to read and understand, so I could be totally wrong in my assumption. If so, please elaborate how to use removeEventListener() or how to use js.Func references correctly.
Comment From: seankhliao
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener :
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.
you're not matching the eventlistener correctly (the useCapture arg).
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
For questions please refer to https://github.com/golang/go/wiki/Questions