Make DEVICE_PIXEL_RATIO work in non-window context

This commit is contained in:
Andreas Hocevar
2020-03-04 15:59:52 +01:00
parent c7f2399e7f
commit 3944a5a038

View File

@@ -37,7 +37,13 @@ export const MAC = ua.indexOf('macintosh') !== -1;
* @type {number}
* @api
*/
export const DEVICE_PIXEL_RATIO = window.devicePixelRatio || 1;
export const DEVICE_PIXEL_RATIO = (function() {
try {
return self.devicePixelRatio;
} catch (e) {
return window.devicePixelRatio || 1;
}
})();
/**
* Image.prototype.decode() is supported.