首页 > 解决方案 > Safari 15 在渲染画布时崩溃

问题描述

macOS、iPhone 和 iPad 上的 Safari 15 在使用画布渲染时会崩溃。有什么解决办法吗?这曾经在以前的 Safari 上工作。

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <script language="javascript">
function init2() {
    const canvas = document.createElement("canvas");
    canvas.style.width = "800px";
    canvas.style.height = "600px";
    canvas.width = 1600;
    canvas.height = 1200;
    document.body.appendChild(canvas);

    var ctx = canvas.getContext('2d');
  ctx.font = '48px system-ui';
  ctx.fillText('Hello World, 你好中文', 10, 50);
}
  </script>
</head>
<body onload="init2()">
</body>
</html>

标签: javascriptcanvassafari

解决方案


最后,我的解决方案是将字体“system-ui”替换为“san-serif”,这解决了我的问题。此外,在 Safari 技术预览版和 Beta 3 中已经修复了这个错误,并计划在 2021 年 10 月晚些时候发布。


推荐阅读