From 33aa7ff161660b819d5661e2d3972e1f3f0be093 Mon Sep 17 00:00:00 2001 From: MoyuScript Date: Wed, 19 Jan 2022 14:45:41 +0800 Subject: [PATCH] fix: Fix documentClone.fonts.ready not resolved even though documentClone.fonts.status is 'loaded' in IOS 13.6 --- src/dom/document-cloner.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/dom/document-cloner.ts b/src/dom/document-cloner.ts index 08faa29..524f3ec 100644 --- a/src/dom/document-cloner.ts +++ b/src/dom/document-cloner.ts @@ -113,7 +113,24 @@ export class DocumentCloner { } if (documentClone.fonts && documentClone.fonts.ready) { - await documentClone.fonts.ready; + // Fix documentClone.fonts.ready not resolved even though documentClone.fonts.status is 'loaded' in IOS 13.6 + + if (documentClone.fonts.status !== 'loaded') { + await Promise.race([ + documentClone.fonts.ready, + new Promise((resolve) => { + const check = () => { + if (documentClone.fonts.status === 'loaded') { + resolve(null); + } else { + setTimeout(check, 100); + } + }; + + setTimeout(check, 100); + }) + ]); + } } if (/(AppleWebKit)/g.test(navigator.userAgent)) {