最近 Chrome 开始发出以下警告:
[违规] 向滚动阻塞“touchmove”事件添加了非被动事件侦听器。考虑将事件处理程序标记为“被动”以使页面响应更快。看https://www.chromestatus.com/feature/5745543795965952 https://www.chromestatus.com/feature/5745543795965952
这些来自 JavaScript Google Maps API 代码。我可以在自己的代码中将 {passive: true} 添加到 addEventListener(),但不知道如何抑制 Google 库中的警告?
这对我有用。去那里https://stackoverflow.com/a/55388961/2233069 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);
};
};
}());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)