aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-20 00:35:56 -0500
committerGitHub <noreply@github.com>2023-12-20 05:35:56 +0000
commite56f03901f21fa8f44725b6a68d3d0dca1e9cd34 (patch)
treee06bc750a01e327760b16d546ce7915cff601394
parent0a0994ca64fceafde05997d93e5ca7d6e5baa7b2 (diff)
Fix case where element style is undefined (#399)
-rw-r--r--ext/js/dom/document-util.js14
1 files changed, 12 insertions, 2 deletions
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