2019-07-23 20:33:22 -07:00
|
|
|
const IS_FIREFOX = process.browser && /Firefox/.test(navigator.userAgent)
|
|
|
|
|
2018-08-31 16:35:26 -07:00
|
|
|
export function decodeImage (img) {
|
2019-07-23 20:33:22 -07:00
|
|
|
// Remove this UA sniff when the Firefox bug is fixed
|
|
|
|
// https://github.com/nolanlawson/pinafore/issues/1344#issuecomment-514312672
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1565542
|
2019-08-17 20:54:45 +03:00
|
|
|
if (!IS_FIREFOX && typeof img.decode === 'function' && !img.src.startsWith('data:image/png;base64,')) {
|
2018-08-22 21:00:53 -07:00
|
|
|
return img.decode()
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
img.onload = resolve
|
|
|
|
img.onerror = reject
|
|
|
|
})
|
|
|
|
}
|