From 9d3bfffc82f00df4caee0315072a1a32b978ce28 Mon Sep 17 00:00:00 2001 From: ycg <1670543365@qq.com> Date: Wed, 28 Sep 2022 13:45:42 +0800 Subject: [PATCH] Fix: toDataURL is not supported for this content on iPhone 7p (#12830) * Fix: toDataURL is not supported for this content on iPhone 7p --- pal/system-info/minigame/system-info.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/pal/system-info/minigame/system-info.ts b/pal/system-info/minigame/system-info.ts index 3fc5de82029..bed493f382b 100644 --- a/pal/system-info/minigame/system-info.ts +++ b/pal/system-info/minigame/system-info.ts @@ -97,13 +97,7 @@ class SystemInfo extends EventTarget { this.isXR = false; // init capability - const _tmpCanvas1 = document.createElement('canvas'); // TODO: remove this - let supportWebp; - try { - supportWebp = TEST ? false : _tmpCanvas1.toDataURL('image/webp').startsWith('data:image/webp'); - } catch (e) { - supportWebp = false; - } + const supportWebp = this._supportsWebp(); const isPCWechat = WECHAT && this.os === OS.WINDOWS && !minigame.isDevTool; this._featureMap = { @@ -126,6 +120,23 @@ class SystemInfo extends EventTarget { this._registerEvent(); } + private _supportsWebp (): boolean { + // NOTE: canvas.toDataURL() is not supported on WeChat iOS end (Found on iPhone 7p) + const isIOSWechat = WECHAT && this.os === OS.IOS; + const _tmpCanvas = document.createElement('canvas'); // TODO: remove this + let supportWebp: boolean; + if (isIOSWechat) { + supportWebp = true; + } else { + try { + supportWebp = TEST ? false : _tmpCanvas.toDataURL('image/webp').startsWith('data:image/webp'); + } catch (e) { + supportWebp = false; + } + } + return supportWebp; + } + private _registerEvent () { minigame.onHide(() => { this.emit('hide');