我在我的网站上嵌入了一个 youtube iframe,它在我的控制台中抛出了以下警告:
[违规] 向阻止滚动的“touchstart”事件添加了非被动事件监听器。考虑将事件处理程序标记为“被动”以使页面更具响应性。见 https://www.chromestatus.com/feature/5745543795965952 base.js:4560
[违规] 'setTimeout' 处理程序耗时 115 毫秒 www-embed-player.js:583
我确定它是这个组件,因为当我将其注释掉时,警告就会停止。我想摆脱这些警告。这个怎么做?
<iframe width="100%" height="300px" src="https://www.youtube.com/embed/wHcyxs6pGIk" frameborder="0" allow="accelerometer; autoplay; gyroscope; picture-in-picture" allowfullscreen></iframe>
最佳答案
我一直有同样的错误。这是我看到的唯一一篇解决这个问题的帖子。在链接中,警告会指示您查看:Github EventListenerOptions/explainer.md
在文件中,它说:
There are a few more complicated scenarios where the handler only wants to suppress scrolling under certain conditions, such as: ... A UI element (like YouTube's volume slider) which slides on horizontal wheel events without changing the scrolling behavior on vertical wheel events. Since there is no equivalent of "touch-action" for wheel events, this case can only be implemented with non-passive wheel listeners.
由于 YouTube 的音量 slider ,这个错误似乎是不可避免的。
关于javascript - YouTube iframe 嵌入违规 : non-passive event listener to a scroll-blocking 'touchstart' event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56780548/