emscripten-core/emscripten

Bug: emscripten_set_wheel_callback is passive

Open

#10.091 geöffnet am 20. Dez. 2019

Auf GitHub ansehen
 (6 Kommentare) (1 Reaktion) (0 zugewiesene Personen)C++ (3.519 Forks)batch import
good first bughelp wanted

Repository-Metriken

Stars
 (27.361 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 19T 10h) (147 gemergte PRs in 30 T)

Beschreibung

Repro:

#include <emscripten/emscripten.h>
#include <emscripten/html5.h>

int callback(int a, const EmscriptenWheelEvent* b, void* c) {
  return EM_TRUE; // Call preventDefault() on the event
}

int main() {
  emscripten_set_wheel_callback(0, 0, 0, callback);
  return 0;
}

Compile the above with 1.38.43-upstream and embed in a HTML file with <script src="a.out.js"></script>. Open the HTML file and scroll with the mouse wheel.

Unexpected: Chrome prints out this to the console:

[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/6662647093133312

The fix is to add {passive: false} to the call to addEventListener like this:

window.addEventListener("wheel", callback, {passive: false});

Ideally this would be configurable in the emscripten_set_wheel_callback API call, but I don't see a way to do that.

See https://developers.google.com/web/updates/2017/01/scrolling-intervention for more information.

Contributor Guide