Skip to content

Commit

Permalink
Fix: toDataURL is not supported for this content on iPhone 7p (#12830)
Browse files Browse the repository at this point in the history
* Fix: toDataURL is not supported for this content on iPhone 7p
  • Loading branch information
yyycggg committed Sep 28, 2022
1 parent e7d11db commit 9d3bfff
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions pal/system-info/minigame/system-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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');
Expand Down

0 comments on commit 9d3bfff

Please sign in to comment.