首页 > 解决方案 > 在 Safari 网络检查器中,是否可以在除指定事件之外的所有事件上停止?

问题描述

我有一个在外窗口内有一个内窗格的 webapp。
用户可以通过两指捏合来放大内部窗格,而无需放大外部窗口。

在 Android 上的 Chrome 上,该应用程序按预期运行。
但是 iOS 设备 (iPad) 上的 Safari,在内部窗格内放大,实际上放大了整个窗口,这不是预期的行为。

我在这里读到iphone/ipad 可以触发意外事件。

我想找到这个活动。
我通过将 iPad 连接到 Macbook 并通过 Safari 进行调试来远程调试 webapp iOS Safari。

在 Safari Web Inspector、Sources选项卡、Breakpoints部分中,我添加了All Events.
当我触摸窗格时,代码在ontouchstart事件中按预期中断,这不是违规事件。

我可以按名称添加要中断的特定事件。
但是因为我不知道哪个是违规事件,所以我想打破除该事件之外的所有ontouchstart事件。

是否可以停止 Safari 中除指定事件之外的所有事件?

谢谢

标签: javascriptsafari-web-inspector

解决方案


我没有发现是否有可能打破除特定事件之外的所有事件。

我最近发现了这个链接,它全面解释了 Safari 中的各种断点选项。
链接的作者亲切地回答了我的问题:

Currently there is no way to exclude specific events.  
In your scenario, is it really necessary to add listeners for all events, or is it a known list of specific events (e.g. all touch and mouse)?  
If it's the latter, I'd suggest just adding a global event listener breakpoint for each event other than the one event you want to exclude.  
Another option might be to configure an All Events global event listener breakpoint with a condition of something like window.event.type !== "..."  
(note that this will only work in Safari Technology Preview 114 or newer).  

ps
我的问题的原因是上游违规事件侦听器。
因为问题出在目标事件上游的事件侦听器中,所以它无助于中断除特定事件之外的所有事件。
我最终通过使用 addEventListener 解决了我最初的问题passive = false,并使用preventDefault()它来防止在冒泡阶段触发上游事件处理程序。


推荐阅读