:visited
这实际上是有意的,以减轻如果要绘制链接可能发生的隐私泄漏。这是讨论此问题的规格问题。基本上,一个邪恶的网站可以通过仅对此类链接
应用 a 来判断哪个链接已被访问,并检查 PaintWorklet 是否已被调用。
因此,Chrome 团队提出的当前解决方案是简单地为所有具有属性的锚点禁用 PaintWorklet,直到根本问题得到正确解决(但这需要时间)。paint()
href
目前,要解决该问题,您必须将锚元素包装在另一个元素中,然后在该包装元素上应用油漆。
(请注意,该错误也会影响内部元素,因此如果您想将该涂料应用于锚点内的元素,那将变得更加复杂......)
const url = URL.createObjectURL( new Blob( [ `
class GreenPainter {
paint(ctx, size, props) {
ctx.fillStyle = "green";
ctx.fillRect(0, 0, size.width, size.height);
}
}
registerPaint('green', GreenPainter);
` ], { type:"text/javascript"} ));
CSS.paintWorklet.addModule(url);
.paint-me {
background: paint(green);
}
div.paint-me {
display: inline-block;
}
<a href="" class="paint-me">
reproduces the bug
</a>
<div class="paint-me">
<a href="">
works around the bug
</a>
</div>