1
0
Эх сурвалжийг харах

ensure computed style is defined

Gildas 7 жил өмнө
parent
commit
5de35d7f32

+ 9 - 6
lib/single-file/doc-helper.js

@@ -263,12 +263,15 @@ this.docHelper = this.docHelper || (() => {
 			const data = [];
 			doc.querySelectorAll("img[src]:not([srcset])").forEach((imageElement, imageElementIndex) => {
 				const computedStyle = win.getComputedStyle(imageElement);
-				let imageData = {}, size = getSize(win, imageElement);
-				if (imageElement.src && size && (!computedStyle.getPropertyValue("background-image") || computedStyle.getPropertyValue("background-image") == "none")) {
-					imageElement.setAttribute(imagesAttributeName(options.sessionId), imageElementIndex);
-					imageData = size;
-					imageData.objectFit = computedStyle.getPropertyValue("object-fit");
-					imageData.objectPosition = computedStyle.getPropertyValue("object-position");
+				let imageData = {};
+				if (computedStyle) {
+					let size = getSize(win, imageElement);
+					if (imageElement.src && size && (!computedStyle.getPropertyValue("background-image") || computedStyle.getPropertyValue("background-image") == "none")) {
+						imageElement.setAttribute(imagesAttributeName(options.sessionId), imageElementIndex);
+						imageData = size;
+						imageData.objectFit = computedStyle.getPropertyValue("object-fit");
+						imageData.objectPosition = computedStyle.getPropertyValue("object-position");
+					}
 				}
 				data.push(imageData);
 			});