From 24688ac608679a76c2ccbb6448101198206ec942 Mon Sep 17 00:00:00 2001 From: kete Date: Tue, 18 Jan 2022 15:43:08 +0800 Subject: [PATCH] fix(font load): fix when font load timeout --- src/dom/document-cloner.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/dom/document-cloner.ts b/src/dom/document-cloner.ts index b04ea8d..859e1db 100644 --- a/src/dom/document-cloner.ts +++ b/src/dom/document-cloner.ts @@ -109,8 +109,18 @@ export class DocumentCloner { return Promise.reject(`Error finding the ${this.referenceElement.nodeName} in the cloned document`); } - if (documentClone.fonts && documentClone.fonts.status === 'loading' && documentClone.fonts.ready) { - await documentClone.fonts.ready; + if (documentClone.fonts && documentClone.fonts.status === 'loading') { + return Promise.race([ + documentClone.fonts.ready, + new Promise((resolve) => { + const fontLoadTimer = setInterval(() => { + if (documentClone.fonts.status === 'loaded') { + clearInterval(fontLoadTimer); + resolve(); + } + }, 1000); + }) + ]); } if (/(AppleWebKit)/g.test(navigator.userAgent)) {