I am struggling with a JS library misbehaving on S...
# javascript
h
I am struggling with a JS library misbehaving on Safari/mac. In a listener triggered on page unload, I need to return nothing in order to avoid a dialog alert to users. But on Safari, the event object has
returnValue: "kotlin.Unit"
(where my Firefox/Ubuntu has
returnValue: ""
). Is this something known? Is there a workaround?
s
There isnt
nothing
even in javascript.
Maybe you want to return
null
?
h
I want the same value to be set for the unload event's
returnValue
in Safari and other browsers. My firefox reports it to be the empty string, and that's ok by me.
The point isn't what this function returns or not, I believe, but that the event object seems to be tampered with in the background somehow ...
Here's the event object in Firefox:
... And here is what I get in Safari (from a mac where I have no user rights and couldn't upload a screenshot anywhere):
... so why, while these two browsers here use the same version of the JS lib, why does the
returnValue
thing vecome the string
kotlin.Unit
on Safari? Is this a bug in transpiliation of the kotlin std lib to JS?
s
Its odd that its different but you can probably fix it by returning
null
in your handler
I suggest you submit a bug report about it
z
If returning
null
doesn't fix it, you might be able to return
undefined
instead.
s
Its typed
((BeforeUnloadEvent) -> String?)?
. I wonder how he even got
Unit
in there
h
Well, you see that the Firefox version has the empty string, not Unit (or undefined). My listener is added using kotlin's addEventListener function, so it's defined as
((Event) -> Unit)?
. According to all documentation I have read, it should be sufficient that the listener method/function not return a string, and indeed, this seems to be the case for all browsers but one. But then I find this discrepancy inside the event object... So I was thinking maybe there was a special handling of the event object initialization going on in Safari ...
s
Please report this as a bug
h
Never reported a bug to youtrack before, so I hope I managed to do it correctly. Here: https://youtrack.jetbrains.com/issue/KT-33985
👍 1