single-file-core 1.6.37 → 1.6.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/helper.js
CHANGED
|
@@ -1011,12 +1011,6 @@ function getResourcesInfo(win, doc, element, options, data, elementHidden, compu
|
|
|
1011
1011
|
}
|
|
1012
1012
|
}
|
|
1013
1013
|
}
|
|
1014
|
-
if (tagName == "IFRAME") {
|
|
1015
|
-
if (elementHidden && options.removeHiddenElements) {
|
|
1016
|
-
element.setAttribute(HIDDEN_FRAME_ATTRIBUTE_NAME, "");
|
|
1017
|
-
data.markedElements.push(element);
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
1014
|
if (tagName == "INPUT") {
|
|
1021
1015
|
if (element.type != "password") {
|
|
1022
1016
|
element.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, element.value);
|
|
@@ -1198,8 +1192,7 @@ function testHiddenElement(element, computedStyle) {
|
|
|
1198
1192
|
const display = computedStyle.getPropertyValue("display");
|
|
1199
1193
|
const opacity = computedStyle.getPropertyValue("opacity");
|
|
1200
1194
|
const visibility = computedStyle.getPropertyValue("visibility");
|
|
1201
|
-
|
|
1202
|
-
hidden = display == "none" || (visibility == "hidden" && tagName == "IFRAME");
|
|
1195
|
+
hidden = display == "none";
|
|
1203
1196
|
if (!hidden && (opacity == "0" || visibility == "hidden") && element.getBoundingClientRect) {
|
|
1204
1197
|
const boundingRect = element.getBoundingClientRect();
|
|
1205
1198
|
hidden = !boundingRect.width && !boundingRect.height;
|
package/core/index.js
CHANGED
|
@@ -1770,6 +1770,8 @@ class Processor {
|
|
|
1770
1770
|
this.stats.add("discarded", "frames", 1);
|
|
1771
1771
|
}
|
|
1772
1772
|
}
|
|
1773
|
+
} else if (frameElement.getAttribute(util.HIDDEN_FRAME_ATTRIBUTE_NAME) == "") {
|
|
1774
|
+
this.stats.add("discarded", "frames", 1);
|
|
1773
1775
|
}
|
|
1774
1776
|
}));
|
|
1775
1777
|
capturedFrames.forEach(capturedFrame => {
|
package/package.json
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
ON_BEFORE_CAPTURE_EVENT_NAME,
|
|
27
27
|
ON_AFTER_CAPTURE_EVENT_NAME,
|
|
28
28
|
WIN_ID_ATTRIBUTE_NAME,
|
|
29
|
+
HIDDEN_FRAME_ATTRIBUTE_NAME,
|
|
29
30
|
WAIT_FOR_USERSCRIPT_PROPERTY_NAME,
|
|
30
31
|
MESSAGE_PREFIX,
|
|
31
32
|
preProcessDoc,
|
|
@@ -39,6 +40,7 @@ const helper = {
|
|
|
39
40
|
ON_BEFORE_CAPTURE_EVENT_NAME,
|
|
40
41
|
ON_AFTER_CAPTURE_EVENT_NAME,
|
|
41
42
|
WIN_ID_ATTRIBUTE_NAME,
|
|
43
|
+
HIDDEN_FRAME_ATTRIBUTE_NAME,
|
|
42
44
|
WAIT_FOR_USERSCRIPT_PROPERTY_NAME,
|
|
43
45
|
preProcessDoc,
|
|
44
46
|
serialize,
|
|
@@ -303,6 +305,7 @@ function initResponse(message) {
|
|
|
303
305
|
}
|
|
304
306
|
function processFrames(doc, options, parentWindowId, sessionId, waitForFrames) {
|
|
305
307
|
const frameElements = getFrames(doc);
|
|
308
|
+
markHiddenFrames(frameElements, options);
|
|
306
309
|
processFramesAsync(doc, frameElements, options, parentWindowId, sessionId, waitForFrames);
|
|
307
310
|
if (frameElements.length) {
|
|
308
311
|
processFramesSync(doc, frameElements, options, parentWindowId, sessionId, waitForFrames);
|
|
@@ -319,12 +322,18 @@ function processFramesAsync(doc, frameElements, options, parentWindowId, session
|
|
|
319
322
|
sessions.set(sessionId, { requestTimeouts });
|
|
320
323
|
}
|
|
321
324
|
frameElements.forEach((frameElement, frameIndex) => {
|
|
325
|
+
if (isHiddenFrame(frameElement)) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
322
328
|
const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;
|
|
323
329
|
frameElement.setAttribute(helper.WIN_ID_ATTRIBUTE_NAME, windowId);
|
|
324
330
|
frames.push({ windowId });
|
|
325
331
|
});
|
|
326
332
|
sendInitResponse({ frames, sessionId, requestedFrameId: doc.documentElement.dataset.requestedFrameId && parentWindowId });
|
|
327
333
|
frameElements.forEach((frameElement, frameIndex) => {
|
|
334
|
+
if (isHiddenFrame(frameElement)) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
328
337
|
const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;
|
|
329
338
|
try {
|
|
330
339
|
sendMessage(frameElement.contentWindow, { method: INIT_REQUEST_MESSAGE, windowId, sessionId, options: RUNTIME_MESSAGING ? undefined : options, scrolling: frameElement.scrolling, waitForFrames });
|
|
@@ -341,6 +350,9 @@ function processFramesAsync(doc, frameElements, options, parentWindowId, session
|
|
|
341
350
|
function processFramesSync(doc, frameElements, options, parentWindowId, sessionId, waitForFrames) {
|
|
342
351
|
const frames = [];
|
|
343
352
|
frameElements.forEach((frameElement, frameIndex) => {
|
|
353
|
+
if (isHiddenFrame(frameElement)) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
344
356
|
const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;
|
|
345
357
|
let frameDoc, frameWindow;
|
|
346
358
|
try {
|
|
@@ -430,6 +442,7 @@ function cleanupFrames(frameElements, parentWindowId, sessionId) {
|
|
|
430
442
|
frameElements.forEach((frameElement, frameIndex) => {
|
|
431
443
|
const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;
|
|
432
444
|
frameElement.removeAttribute(helper.WIN_ID_ATTRIBUTE_NAME);
|
|
445
|
+
frameElement.removeAttribute(helper.HIDDEN_FRAME_ATTRIBUTE_NAME);
|
|
433
446
|
try {
|
|
434
447
|
sendMessage(frameElement.contentWindow, { method: CLEANUP_REQUEST_MESSAGE, windowId, sessionId });
|
|
435
448
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -519,4 +532,39 @@ function getFrames(document) {
|
|
|
519
532
|
}
|
|
520
533
|
});
|
|
521
534
|
return frames;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// hidden frames are marked and left out of the tree: their content is dropped anyway when hidden
|
|
538
|
+
// elements are removed, and each one would otherwise cost up to the ack timeout; the frames keep
|
|
539
|
+
// their index in the list, which is what the cleanup numbers them by
|
|
540
|
+
function markHiddenFrames(frameElements, options) {
|
|
541
|
+
frameElements.forEach(frameElement => {
|
|
542
|
+
if (options.removeHiddenElements && testHiddenFrame(frameElement)) {
|
|
543
|
+
frameElement.setAttribute(helper.HIDDEN_FRAME_ATTRIBUTE_NAME, "");
|
|
544
|
+
} else {
|
|
545
|
+
frameElement.removeAttribute(helper.HIDDEN_FRAME_ATTRIBUTE_NAME);
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function isHiddenFrame(frameElement) {
|
|
551
|
+
return frameElement.getAttribute(helper.HIDDEN_FRAME_ATTRIBUTE_NAME) == "";
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// a frame is a replaced element: nothing in it can overflow its box, and its document cannot undo
|
|
555
|
+
// the visibility set on the element, so a frame with no box or not painted shows nothing, whatever it
|
|
556
|
+
// holds; an opacity of 0 is left alone, it is how an embed fades in once loaded
|
|
557
|
+
function testHiddenFrame(frameElement) {
|
|
558
|
+
try {
|
|
559
|
+
const win = frameElement.ownerDocument.defaultView;
|
|
560
|
+
const computedStyle = win.getComputedStyle(frameElement);
|
|
561
|
+
if (computedStyle.getPropertyValue("display") == "none" || computedStyle.getPropertyValue("visibility") == "hidden") {
|
|
562
|
+
return true;
|
|
563
|
+
}
|
|
564
|
+
const boundingRect = frameElement.getBoundingClientRect();
|
|
565
|
+
return !boundingRect.width && !boundingRect.height;
|
|
566
|
+
// eslint-disable-next-line no-unused-vars
|
|
567
|
+
} catch (error) {
|
|
568
|
+
return false;
|
|
569
|
+
}
|
|
522
570
|
}
|