From e56f03901f21fa8f44725b6a68d3d0dca1e9cd34 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 20 Dec 2023 00:35:56 -0500 Subject: Fix case where element style is undefined (#399) --- ext/js/dom/document-util.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'ext/js') diff --git a/ext/js/dom/document-util.js b/ext/js/dom/document-util.js index 9e4f451a..d335eba3 100644 --- a/ext/js/dom/document-util.js +++ b/ext/js/dom/document-util.js @@ -230,8 +230,7 @@ export class DocumentUtil { */ static computeZoomScale(node) { if (this._cssZoomSupported === null) { - // @ts-expect-error - zoom is a non-standard property that exists in Chromium-based browsers - this._cssZoomSupported = (typeof document.createElement('div').style.zoom === 'string'); + this._cssZoomSupported = this._computeCssZoomSupported(); } if (!this._cssZoomSupported) { return 1; } // documentElement must be excluded because the computer style of its zoom property is inconsistent. @@ -1075,6 +1074,17 @@ export class DocumentUtil { } return !Number.isNaN(value) ? value : null; } + + /** + * Computes whether or not this browser and document supports CSS zoom, which is primarily a legacy Chromium feature. + * @returns {boolean} + */ + static _computeCssZoomSupported() { + // 'style' can be undefined in certain contexts, such as when document is an SVG document. + const {style} = document.createElement('div'); + // @ts-expect-error - zoom is a non-standard property. + return (typeof style === 'object' && style !== null && typeof style.zoom === 'string'); + } } /** @type {RegExp} */ // eslint-disable-next-line no-underscore-dangle -- cgit v1.2.3