Javascript Google Maps API & non-passive event handlers

4.9k views Asked by At

Recently Chrome started emitting the following warnings:

[Violation] Added non-passive event listener to a scroll-blocking 'touchmove' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952

These are coming from the JavaScript Google Maps API code. I'm able to add {passive: true} to addEventListener() in my own code but don't know how to suppress the warning in Googles libraries?

2

There are 2 answers

0
djdance On

this works for me. Got here https://stackoverflow.com/a/55388961/2233069

(function () {
    if (typeof EventTarget !== "undefined") {
        let func = EventTarget.prototype.addEventListener;
        EventTarget.prototype.addEventListener = function (type, fn, capture) {
            this.func = func;
            if(typeof capture !== "boolean"){
                capture = capture || {};
                capture.passive = false;
            }
            this.func(type, fn, capture);
        };
    };
}());
1
bytes4me On

There is nothing you can do at this point. It's a warning that is generated from Googles own API code. As long as your own event listeners are passive, I think it can be safely ignored.