Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case where element style is undefined #399

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions ext/js/dom/document-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down