You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Adding/removing hooks for the beforeunload event with Dom_html.window##.onbeforeunload := Dom_html.handler … is not working out-of-the-box with both Chromium, Firefox, and Safari. So I had to devise the following hack (unsafe JS code):
letprompt_before_unload() : unit =Js.Unsafe.js_expr "window.onbeforeunload = function(e) {e.preventDefault(); return false;}"inletresume_before_unload() : unit =Js.Unsafe.js_expr "window.onbeforeunload = null"in
(…)
ifnot sync then prompt_before_unload ()else resume_before_unload ()
(…)
Expected behavior
I open this PR in case it is possible for you to tweak Dom_html.handler, and be able to directly use js_of_ocaml's abstractions (notJs.Unsafe.js_expr) for this use case, and stay compatible with (Chromium, Firefox, Safari…)
FTR → I had sketched a possible explanation of why one such tentative code doesn't work in Firefox here: ocaml-sf/learn-ocaml#467 (comment)
Anyway, if ever you'd think it is already possible to implement the snippet above without Js.Unsafe.js_expr (meaning there's no "bug" over there), I'm taker of any idiomatic snippet 👍
Versions
Version of packages used to reproduce the bug:
ocaml 4.12.1
js_of_ocaml 3.9.0
(I'll be happy to provide more details on the versions used if need be)
Thanks a lot, @hhugo ! Your approach looks better indeed :)
I'll test this as soon as possible in learn-ocaml.
Just asking in the meantime: do you believe the prompt_before_unload could itself be rewritten directly as an instance of Dom_html.handler ? possibly, modifying/generalizing Dom_html.handler's implementation…
See also ocaml-sf/learn-ocaml#467 (comment)
Anyway, more testing is needed! (and sorry if I can't send more feedback quickly enough…)
Just asking in the meantime: do you believe the prompt_before_unload could itself be rewritten directly as an instance of Dom_html.handler ? possibly, modifying/generalizing Dom_html.handler's implementation…
I'm not sure, you should keep this issue open until one figure out what to do.
Describe the bug
Adding/removing hooks for the beforeunload event with
Dom_html.window##.onbeforeunload := Dom_html.handler …
is not working out-of-the-box with both Chromium, Firefox, and Safari. So I had to devise the following hack (unsafe JS code):— Source code: https://github.com/ocaml-sf/learn-ocaml/blob/a6e4c5e6/src/app/learnocaml_exercise_main.ml#L292-L310
Expected behavior
I open this PR in case it is possible for you to tweak
Dom_html.handler
, and be able to directly use js_of_ocaml's abstractions (notJs.Unsafe.js_expr
) for this use case, and stay compatible with (Chromium, Firefox, Safari…)FTR → I had sketched a possible explanation of why one such tentative code doesn't work in Firefox here:
ocaml-sf/learn-ocaml#467 (comment)
Anyway, if ever you'd think it is already possible to implement the snippet above without
Js.Unsafe.js_expr
(meaning there's no "bug" over there), I'm taker of any idiomatic snippet 👍Versions
Version of packages used to reproduce the bug:
(I'll be happy to provide more details on the versions used if need be)
Cc @yurug FYI
The text was updated successfully, but these errors were encountered: