简体   繁体   English

如果开发人员控制台处于活动状态,Canvas 无法正常工作

[英]Canvas not working properly if developer console is active

A few days ago, I was wondering about why my canvas is not working properly.几天前,我想知道为什么我的 canvas 不能正常工作。 I'm using szimek's library to create signatures and sometimes those pen strokes looked a bit crazy.我正在使用 szimek 的库来创建签名,有时这些笔画看起来有点疯狂。 I also tested on Edge (which ended in the same result as Chrome) and TOR (worked as it should).我还在 Edge(与 Chrome 的结果相同)和 TOR(按应有的工作)上进行了测试。

Yesterday, I found the solution why this happens randomly.昨天,我找到了为什么这种随机发生的解决方案。 My strokes look crazy during the usage of the browsers developer console when it's open.当浏览器开发者控制台打开时,我的笔触看起来很疯狂。 If it's closed, they're looking normally (when drawing again).如果它已关闭,则它们看起来正常(再次绘制时)。

Does anyone know why this happened or is it caused by it's core engines?有谁知道为什么会发生这种情况,还是由它的核心引擎引起的? Here's an example of what I mean:这是我的意思的一个例子: 在此处输入图像描述

Thank you.谢谢你。

This happens because in Chromium (and in Gecko), as per specs recommendations , UI events like mousemove or pointermove are throttled to the frame refresh rate of the monitor.发生这种情况是因为在 Chromium(和 Gecko)中,根据规范建议mousemovepointermove等 UI 事件被限制为显示器的帧刷新率。

However, in Chromium only and for whatever reason, when the dev tools are open, they emit the raw events...但是,仅在 Chromium 中,无论出于何种原因,当开发工具打开时,它们会发出原始事件......
So when dev tools are closed, even though the hardware pointer (eg mouse) did emit more events, these have been coalesced into a single pointermove event, which may draw lines smoother to the eye since each point have been averaged, but you actually received less data.因此,当开发工具关闭时,即使硬件指针(例如鼠标)确实发出了更多事件,这些事件也已合并为单个指针移动事件,这可能会使线条更平滑,因为每个点都已被平均,但您实际上收到了更少的数据。

You can retrieve the list of raw events from the pointermove event's getCoallescedEvents , as exposed in this other answer of mine, and from these you could also build up the coalescing logic yourself if needed (using requestAnimationFrame() as a throttler, that's exactly what Chromium does).您可以从pointermove事件的getCoallescedEvents中检索原始事件列表,正如我的另一个答案中所公开的那样,如果需要,您还可以自己构建合并逻辑(使用requestAnimationFrame()作为节流器,这正是 Chromium做)。

As to why Chromium does disable the coalescing when dev-tools are open... that's still a mystery for me, but I never got enough incentive to look this up.至于为什么 Chromium 在开发工具打开时会禁用合并……这对我来说仍然是个谜,但我从来没有足够的动力去查看它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM