eyes_selenium 3.15.31 → 3.15.32
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.
- checksums.yaml +4 -4
- data/lib/applitools/selenium/scripts/process_page_and_poll.rb +283 -149
- data/lib/applitools/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7597ed29687826c8bbe108972397fdb2cc7976eec8cb13ee4dd1a64e04595f79
|
4
|
+
data.tar.gz: f586de41503704289ccef067b8b5fd35242de9d5c6817dff8ed8a67e5d50e008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4c440899e2df919f89d226f737a18fa4f2bf869e0a217a79eb7a8f1d96977ff8cf53e99260aaa636390b86b5873f00ef4a46352057df7afc9d8d83f4356b144
|
7
|
+
data.tar.gz: 7f2024b0a8e8f6304ff7d9d829f8499c852cc84633953ec579c0ce89df951b6052debfd9c5fe47f9d364da39e5a3932fe23e952b75a31a6c1d14e775c2be72c9
|
@@ -2,7 +2,7 @@ module Applitools
|
|
2
2
|
module Selenium
|
3
3
|
module Scripts
|
4
4
|
PROCESS_PAGE_AND_POLL = <<'END'
|
5
|
-
/* @applitools/dom-snapshot@
|
5
|
+
/* @applitools/dom-snapshot@2.2.1 */
|
6
6
|
|
7
7
|
function __processPageAndPoll() {
|
8
8
|
var processPageAndPoll = (function () {
|
@@ -65,14 +65,14 @@ function __processPageAndPoll() {
|
|
65
65
|
.map(srcsetEl =>
|
66
66
|
srcsetEl
|
67
67
|
.getAttribute('srcset')
|
68
|
-
.split(',')
|
68
|
+
.split(', ')
|
69
69
|
.map(str => str.trim().split(/\s+/)[0]),
|
70
70
|
)
|
71
71
|
.reduce((acc, urls) => acc.concat(urls), []);
|
72
72
|
|
73
|
-
const srcUrls = Array.from(
|
74
|
-
|
75
|
-
);
|
73
|
+
const srcUrls = Array.from(
|
74
|
+
doc.querySelectorAll('img[src],source[src],input[type="image"][src]'),
|
75
|
+
).map(srcEl => srcEl.getAttribute('src'));
|
76
76
|
|
77
77
|
const imageUrls = Array.from(doc.querySelectorAll('image,use'))
|
78
78
|
.map(hrefEl => hrefEl.getAttribute('href') || hrefEl.getAttribute('xlink:href'))
|
@@ -100,12 +100,6 @@ function __processPageAndPoll() {
|
|
100
100
|
|
101
101
|
var extractLinks_1 = extractLinks;
|
102
102
|
|
103
|
-
function absolutizeUrl(url, absoluteUrl) {
|
104
|
-
return new URL(url, absoluteUrl).href;
|
105
|
-
}
|
106
|
-
|
107
|
-
var absolutizeUrl_1 = absolutizeUrl;
|
108
|
-
|
109
103
|
function uuid() {
|
110
104
|
return window.crypto.getRandomValues(new Uint32Array(1))[0];
|
111
105
|
}
|
@@ -114,13 +108,33 @@ function __processPageAndPoll() {
|
|
114
108
|
|
115
109
|
function isInlineFrame(frame) {
|
116
110
|
return (
|
117
|
-
|
111
|
+
!/^https?:.+/.test(frame.src) ||
|
112
|
+
(frame.contentDocument &&
|
113
|
+
frame.contentDocument.location &&
|
114
|
+
frame.contentDocument.location.href === 'about:blank')
|
118
115
|
);
|
119
116
|
}
|
120
117
|
|
121
118
|
var isInlineFrame_1 = isInlineFrame;
|
122
119
|
|
123
|
-
function
|
120
|
+
function isAccessibleFrame(frame) {
|
121
|
+
try {
|
122
|
+
const doc = frame.contentDocument;
|
123
|
+
return !!(doc && doc.defaultView && doc.defaultView.frameElement);
|
124
|
+
} catch (err) {
|
125
|
+
// for CORS frames
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
var isAccessibleFrame_1 = isAccessibleFrame;
|
130
|
+
|
131
|
+
function absolutizeUrl(url, absoluteUrl) {
|
132
|
+
return new URL(url, absoluteUrl).href;
|
133
|
+
}
|
134
|
+
|
135
|
+
var absolutizeUrl_1 = absolutizeUrl;
|
136
|
+
|
137
|
+
function domNodesToCdt(docNode, baseUrl) {
|
124
138
|
const cdt = [{nodeType: Node.DOCUMENT_NODE}];
|
125
139
|
const docRoots = [docNode];
|
126
140
|
const canvasElements = [];
|
@@ -143,9 +157,8 @@ function __processPageAndPoll() {
|
|
143
157
|
}
|
144
158
|
|
145
159
|
function elementNodeFactory(cdt, elementNode) {
|
146
|
-
let node, manualChildNodeIndexes;
|
160
|
+
let node, manualChildNodeIndexes, dummyUrl;
|
147
161
|
const {nodeType} = elementNode;
|
148
|
-
let dummyUrl, frameBase;
|
149
162
|
|
150
163
|
if ([Node.ELEMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE].includes(nodeType)) {
|
151
164
|
if (elementNode.nodeName !== 'SCRIPT') {
|
@@ -169,14 +182,17 @@ function __processPageAndPoll() {
|
|
169
182
|
}
|
170
183
|
|
171
184
|
if (elementNode.nodeName === 'CANVAS') {
|
172
|
-
dummyUrl = absolutizeUrl_1(`applitools-canvas-${uuid_1()}.png`,
|
185
|
+
dummyUrl = absolutizeUrl_1(`applitools-canvas-${uuid_1()}.png`, baseUrl);
|
173
186
|
node.attributes.push({name: 'data-applitools-src', value: dummyUrl});
|
174
187
|
canvasElements.push({element: elementNode, url: dummyUrl});
|
175
188
|
}
|
176
189
|
|
177
|
-
if (
|
178
|
-
|
179
|
-
|
190
|
+
if (
|
191
|
+
elementNode.nodeName === 'IFRAME' &&
|
192
|
+
isAccessibleFrame_1(elementNode) &&
|
193
|
+
isInlineFrame_1(elementNode)
|
194
|
+
) {
|
195
|
+
dummyUrl = absolutizeUrl_1(`?applitools-iframe=${uuid_1()}`, baseUrl);
|
180
196
|
node.attributes.push({name: 'data-applitools-src', value: dummyUrl});
|
181
197
|
inlineFrames.push({element: elementNode, url: dummyUrl});
|
182
198
|
}
|
@@ -279,16 +295,6 @@ function __processPageAndPoll() {
|
|
279
295
|
nodeName: elementNode.nodeName,
|
280
296
|
};
|
281
297
|
}
|
282
|
-
|
283
|
-
function getFrameBaseUrl(frameElement) {
|
284
|
-
const href =
|
285
|
-
frameElement.contentDocument.querySelectorAll('base') &&
|
286
|
-
frameElement.contentDocument.querySelectorAll('base')[0] &&
|
287
|
-
frameElement.contentDocument.querySelectorAll('base')[0].href;
|
288
|
-
if (href && !href.includes('about:blank')) {
|
289
|
-
return href;
|
290
|
-
}
|
291
|
-
}
|
292
298
|
}
|
293
299
|
|
294
300
|
var domNodesToCdt_1 = domNodesToCdt;
|
@@ -314,9 +320,9 @@ function __processPageAndPoll() {
|
|
314
320
|
var aggregateResourceUrlsAndBlobs_1 = aggregateResourceUrlsAndBlobs;
|
315
321
|
|
316
322
|
function makeGetResourceUrlsAndBlobs({processResource, aggregateResourceUrlsAndBlobs}) {
|
317
|
-
return function getResourceUrlsAndBlobs(documents,
|
323
|
+
return function getResourceUrlsAndBlobs({documents, urls, forceCreateStyle = false}) {
|
318
324
|
return Promise.all(
|
319
|
-
urls.map(url => processResource(url, documents,
|
325
|
+
urls.map(url => processResource({url, documents, getResourceUrlsAndBlobs, forceCreateStyle})),
|
320
326
|
).then(resourceUrlsAndBlobsArr => aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr));
|
321
327
|
};
|
322
328
|
}
|
@@ -337,63 +343,48 @@ function __processPageAndPoll() {
|
|
337
343
|
|
338
344
|
var toUnAnchoredUri_1 = toUnAnchoredUri;
|
339
345
|
|
340
|
-
|
341
|
-
if (!cssContent) {
|
342
|
-
console.log('[dom-snapshot] error createTempStylsheet called without cssContent');
|
343
|
-
return;
|
344
|
-
}
|
345
|
-
const head = document.head || document.querySelectorAll('head')[0];
|
346
|
-
const style = document.createElement('style');
|
347
|
-
style.type = 'text/css';
|
348
|
-
style.setAttribute('data-desc', 'Applitools tmp variable created by DOM SNAPSHOT');
|
349
|
-
head.appendChild(style);
|
350
|
-
|
351
|
-
// This is required for IE8 and below.
|
352
|
-
if (style.styleSheet) {
|
353
|
-
style.styleSheet.cssText = cssContent;
|
354
|
-
} else {
|
355
|
-
style.appendChild(document.createTextNode(cssContent));
|
356
|
-
}
|
357
|
-
return style.sheet;
|
358
|
-
}
|
346
|
+
var noop = () => {};
|
359
347
|
|
360
|
-
|
361
|
-
|
362
|
-
function makeExtractResourcesFromStyle({extractResourcesFromStyleSheet}) {
|
363
|
-
return function extractResourcesFromStyle(styleSheet, cssContent, doc = document) {
|
364
|
-
let corsFreeStyleSheet;
|
365
|
-
try {
|
366
|
-
styleSheet.cssRules;
|
367
|
-
corsFreeStyleSheet = styleSheet;
|
368
|
-
} catch (e) {
|
369
|
-
console.log(
|
370
|
-
`[dom-snapshot] could not access cssRules for ${styleSheet.href} ${e}\ncreating temp style for access.`,
|
371
|
-
);
|
372
|
-
corsFreeStyleSheet = createTempStyleSheet(cssContent);
|
373
|
-
}
|
374
|
-
|
375
|
-
const result = extractResourcesFromStyleSheet(corsFreeStyleSheet, doc);
|
376
|
-
if (corsFreeStyleSheet !== styleSheet) {
|
377
|
-
corsFreeStyleSheet.ownerNode.parentNode.removeChild(corsFreeStyleSheet.ownerNode);
|
378
|
-
}
|
379
|
-
return result;
|
380
|
-
};
|
348
|
+
function flat(arr) {
|
349
|
+
return arr.reduce((flatArr, item) => flatArr.concat(item), []);
|
381
350
|
}
|
382
351
|
|
383
|
-
var
|
352
|
+
var flat_1 = flat;
|
384
353
|
|
385
354
|
function makeProcessResource({
|
386
355
|
fetchUrl,
|
387
356
|
findStyleSheetByUrl,
|
357
|
+
getCorsFreeStyleSheet,
|
388
358
|
extractResourcesFromStyleSheet,
|
389
359
|
extractResourcesFromSvg,
|
360
|
+
sessionCache,
|
390
361
|
cache = {},
|
362
|
+
log = noop,
|
391
363
|
}) {
|
392
|
-
|
393
|
-
|
394
|
-
|
364
|
+
return function processResource({
|
365
|
+
url,
|
366
|
+
documents,
|
367
|
+
getResourceUrlsAndBlobs,
|
368
|
+
forceCreateStyle = false,
|
369
|
+
}) {
|
370
|
+
if (!cache[url]) {
|
371
|
+
if (sessionCache && sessionCache.getItem(url)) {
|
372
|
+
const resourceUrls = getDependencies(url);
|
373
|
+
log('doProcessResource from sessionStorage', url, 'deps:', resourceUrls.slice(1));
|
374
|
+
cache[url] = Promise.resolve({resourceUrls});
|
375
|
+
} else {
|
376
|
+
const now = Date.now();
|
377
|
+
cache[url] = doProcessResource(url).then(result => {
|
378
|
+
log('doProcessResource', `[${Date.now() - now}ms]`, url);
|
379
|
+
return result;
|
380
|
+
});
|
381
|
+
}
|
382
|
+
}
|
383
|
+
return cache[url];
|
395
384
|
|
396
385
|
function doProcessResource(url) {
|
386
|
+
log('fetching', url);
|
387
|
+
const now = Date.now();
|
397
388
|
return fetchUrl(url)
|
398
389
|
.catch(e => {
|
399
390
|
if (probablyCORS(e)) {
|
@@ -404,50 +395,81 @@ function __processPageAndPoll() {
|
|
404
395
|
})
|
405
396
|
.then(({url, type, value, probablyCORS}) => {
|
406
397
|
if (probablyCORS) {
|
398
|
+
sessionCache && sessionCache.setItem(url, []);
|
407
399
|
return {resourceUrls: [url]};
|
408
400
|
}
|
409
401
|
|
410
|
-
|
411
|
-
|
402
|
+
log('fetched', `[${Date.now() - now}ms]`, url);
|
403
|
+
|
404
|
+
const thisBlob = {[url]: {type, value}};
|
405
|
+
let dependentUrls;
|
412
406
|
if (/text\/css/.test(type)) {
|
413
|
-
|
414
|
-
if (styleSheet) {
|
415
|
-
|
407
|
+
let styleSheet = findStyleSheetByUrl(url, documents);
|
408
|
+
if (styleSheet || forceCreateStyle) {
|
409
|
+
const {corsFreeStyleSheet, cleanStyleSheet} = getCorsFreeStyleSheet(
|
410
|
+
value,
|
411
|
+
styleSheet,
|
412
|
+
);
|
413
|
+
dependentUrls = extractResourcesFromStyleSheet(corsFreeStyleSheet, documents[0]);
|
414
|
+
cleanStyleSheet();
|
416
415
|
}
|
417
416
|
} else if (/image\/svg/.test(type)) {
|
418
417
|
try {
|
419
|
-
|
418
|
+
dependentUrls = extractResourcesFromSvg(value);
|
419
|
+
forceCreateStyle = !!dependentUrls;
|
420
420
|
} catch (e) {
|
421
421
|
console.log('could not parse svg content', e);
|
422
422
|
}
|
423
423
|
}
|
424
424
|
|
425
|
-
if (
|
426
|
-
|
427
|
-
.map(toUnAnchoredUri_1)
|
425
|
+
if (dependentUrls) {
|
426
|
+
const absoluteDependentUrls = dependentUrls
|
428
427
|
.map(resourceUrl => absolutizeUrl_1(resourceUrl, url.replace(/^blob:/, '')))
|
428
|
+
.map(toUnAnchoredUri_1)
|
429
429
|
.filter(filterInlineUrl_1);
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
430
|
+
|
431
|
+
sessionCache && sessionCache.setItem(url, absoluteDependentUrls);
|
432
|
+
|
433
|
+
return getResourceUrlsAndBlobs({
|
434
|
+
documents,
|
435
|
+
urls: absoluteDependentUrls,
|
436
|
+
forceCreateStyle,
|
437
|
+
}).then(({resourceUrls, blobsObj}) => ({
|
438
|
+
resourceUrls,
|
439
|
+
blobsObj: Object.assign(blobsObj, thisBlob),
|
440
|
+
}));
|
441
|
+
} else {
|
442
|
+
sessionCache && sessionCache.setItem(url, []);
|
443
|
+
return {blobsObj: thisBlob};
|
436
444
|
}
|
437
|
-
return result;
|
438
445
|
})
|
439
446
|
.catch(err => {
|
440
|
-
|
447
|
+
log('error while fetching', url, err);
|
448
|
+
sessionCache && clearFromSessionStorage();
|
441
449
|
return {};
|
442
450
|
});
|
443
451
|
}
|
444
452
|
|
445
453
|
function probablyCORS(err) {
|
446
|
-
const
|
454
|
+
const msg =
|
447
455
|
err.message &&
|
448
456
|
(err.message.includes('Failed to fetch') || err.message.includes('Network request failed'));
|
449
|
-
const
|
450
|
-
return
|
457
|
+
const name = err.name && err.name.includes('TypeError');
|
458
|
+
return msg && name;
|
459
|
+
}
|
460
|
+
|
461
|
+
function getDependencies(url) {
|
462
|
+
const dependentUrls = sessionCache.getItem(url);
|
463
|
+
return [url].concat(dependentUrls ? uniq_1(flat_1(dependentUrls.map(getDependencies))) : []);
|
464
|
+
}
|
465
|
+
|
466
|
+
function clearFromSessionStorage() {
|
467
|
+
log('clearing from sessionStorage:', url);
|
468
|
+
sessionCache.keys().forEach(key => {
|
469
|
+
const dependentUrls = sessionCache.getItem(key);
|
470
|
+
sessionCache.setItem(key, dependentUrls.filter(dep => dep !== url));
|
471
|
+
});
|
472
|
+
log('cleared from sessionStorage:', url);
|
451
473
|
}
|
452
474
|
};
|
453
475
|
}
|
@@ -466,12 +488,6 @@ function __processPageAndPoll() {
|
|
466
488
|
|
467
489
|
var getUrlFromCssText_1 = getUrlFromCssText;
|
468
490
|
|
469
|
-
function flat(arr) {
|
470
|
-
return [].concat(...arr);
|
471
|
-
}
|
472
|
-
|
473
|
-
var flat_1 = flat;
|
474
|
-
|
475
491
|
function makeExtractResourcesFromSvg({parser, decoder, extractResourceUrlsFromStyleTags}) {
|
476
492
|
return function(svgArrayBuffer) {
|
477
493
|
const decooder = decoder || new TextDecoder('utf-8');
|
@@ -479,16 +495,16 @@ function __processPageAndPoll() {
|
|
479
495
|
const domparser = parser || new DOMParser();
|
480
496
|
const doc = domparser.parseFromString(svgStr, 'image/svg+xml');
|
481
497
|
|
482
|
-
const
|
483
|
-
.
|
484
|
-
|
498
|
+
const fromHref = Array.from(doc.querySelectorAll('image,use,link[rel="stylesheet"]')).map(
|
499
|
+
e => e.getAttribute('href') || e.getAttribute('xlink:href'),
|
500
|
+
);
|
485
501
|
const fromObjects = Array.from(doc.getElementsByTagName('object')).map(e =>
|
486
502
|
e.getAttribute('data'),
|
487
503
|
);
|
488
504
|
const fromStyleTags = extractResourceUrlsFromStyleTags(doc, false);
|
489
505
|
const fromStyleAttrs = urlsFromStyleAttrOfDoc(doc);
|
490
506
|
|
491
|
-
return
|
507
|
+
return fromHref
|
492
508
|
.concat(fromObjects)
|
493
509
|
.concat(fromStyleTags)
|
494
510
|
.concat(fromStyleAttrs)
|
@@ -538,7 +554,7 @@ function __processPageAndPoll() {
|
|
538
554
|
function makeExtractResourcesFromStyleSheet({styleSheetCache}) {
|
539
555
|
return function extractResourcesFromStyleSheet(styleSheet, doc) {
|
540
556
|
const win = doc.defaultView || (doc.ownerDocument && doc.ownerDocument.defaultView) || window;
|
541
|
-
|
557
|
+
const urls = uniq_1(
|
542
558
|
Array.from(styleSheet.cssRules || []).reduce((acc, rule) => {
|
543
559
|
if (rule instanceof win.CSSImportRule) {
|
544
560
|
styleSheetCache[rule.styleSheet.href] = rule.styleSheet;
|
@@ -559,6 +575,7 @@ function __processPageAndPoll() {
|
|
559
575
|
return acc;
|
560
576
|
}, []),
|
561
577
|
);
|
578
|
+
return urls.filter(u => u[0] !== '#');
|
562
579
|
};
|
563
580
|
}
|
564
581
|
|
@@ -595,6 +612,52 @@ function __processPageAndPoll() {
|
|
595
612
|
|
596
613
|
var extractResourceUrlsFromStyleTags = makeExtractResourceUrlsFromStyleTags;
|
597
614
|
|
615
|
+
function createTempStylsheet(cssArrayBuffer) {
|
616
|
+
const cssText = new TextDecoder('utf-8').decode(cssArrayBuffer);
|
617
|
+
const head = document.head || document.querySelectorAll('head')[0];
|
618
|
+
const style = document.createElement('style');
|
619
|
+
style.type = 'text/css';
|
620
|
+
style.setAttribute('data-desc', 'Applitools tmp variable created by DOM SNAPSHOT');
|
621
|
+
head.appendChild(style);
|
622
|
+
|
623
|
+
// This is required for IE8 and below.
|
624
|
+
if (style.styleSheet) {
|
625
|
+
style.styleSheet.cssText = cssText;
|
626
|
+
} else {
|
627
|
+
style.appendChild(document.createTextNode(cssText));
|
628
|
+
}
|
629
|
+
return style.sheet;
|
630
|
+
}
|
631
|
+
|
632
|
+
var createTempStyleSheet = createTempStylsheet;
|
633
|
+
|
634
|
+
function getCorsFreeStyleSheet(cssArrayBuffer, styleSheet) {
|
635
|
+
let corsFreeStyleSheet;
|
636
|
+
if (styleSheet) {
|
637
|
+
try {
|
638
|
+
styleSheet.cssRules;
|
639
|
+
corsFreeStyleSheet = styleSheet;
|
640
|
+
} catch (e) {
|
641
|
+
console.log(
|
642
|
+
`[dom-snapshot] could not access cssRules for ${styleSheet.href} ${e}\ncreating temp style for access.`,
|
643
|
+
);
|
644
|
+
corsFreeStyleSheet = createTempStyleSheet(cssArrayBuffer);
|
645
|
+
}
|
646
|
+
} else {
|
647
|
+
corsFreeStyleSheet = createTempStyleSheet(cssArrayBuffer);
|
648
|
+
}
|
649
|
+
|
650
|
+
return {corsFreeStyleSheet, cleanStyleSheet};
|
651
|
+
|
652
|
+
function cleanStyleSheet() {
|
653
|
+
if (corsFreeStyleSheet !== styleSheet) {
|
654
|
+
corsFreeStyleSheet.ownerNode.parentNode.removeChild(corsFreeStyleSheet.ownerNode);
|
655
|
+
}
|
656
|
+
}
|
657
|
+
}
|
658
|
+
|
659
|
+
var getCorsFreeStyleSheet_1 = getCorsFreeStyleSheet;
|
660
|
+
|
598
661
|
function base64ToArrayBuffer(base64) {
|
599
662
|
var binary_string = window.atob(base64);
|
600
663
|
var len = binary_string.length;
|
@@ -621,34 +684,23 @@ function __processPageAndPoll() {
|
|
621
684
|
const iframes = flat_1(
|
622
685
|
documents.map(d => Array.from(d.querySelectorAll('iframe[src]:not([src=""])'))),
|
623
686
|
);
|
624
|
-
return iframes
|
625
|
-
.filter(f => isAccessibleFrame(f) && !isInlineFrame_1(f))
|
626
|
-
.map(f => f.contentDocument);
|
627
|
-
}
|
628
687
|
|
629
|
-
|
630
|
-
try {
|
631
|
-
const doc = frame.contentDocument;
|
632
|
-
return !!(doc && doc.defaultView && doc.defaultView.frameElement);
|
633
|
-
} catch (err) {
|
634
|
-
// for CORS frames
|
635
|
-
}
|
688
|
+
return iframes.filter(f => isAccessibleFrame_1(f) && !isInlineFrame_1(f)).map(f => f.contentDocument);
|
636
689
|
}
|
637
690
|
|
638
691
|
var extractFrames_1 = extractFrames;
|
639
692
|
|
640
693
|
const getBaesUrl = function(doc) {
|
641
694
|
const baseUrl = doc.querySelectorAll('base')[0] && doc.querySelectorAll('base')[0].href;
|
642
|
-
if (baseUrl) {
|
695
|
+
if (baseUrl && isUrl(baseUrl)) {
|
643
696
|
return baseUrl;
|
644
697
|
}
|
645
|
-
const frameElement = doc.defaultView && doc.defaultView.frameElement;
|
646
|
-
if (frameElement) {
|
647
|
-
return frameElement.src || getBaesUrl(frameElement.ownerDocument);
|
648
|
-
}
|
649
|
-
return doc.location.href;
|
650
698
|
};
|
651
699
|
|
700
|
+
function isUrl(url) {
|
701
|
+
return url && !/^(about:blank|javascript:void|blob:)/.test(url);
|
702
|
+
}
|
703
|
+
|
652
704
|
var getBaseUrl = getBaesUrl;
|
653
705
|
|
654
706
|
function toUriEncoding(url) {
|
@@ -664,7 +716,70 @@ function __processPageAndPoll() {
|
|
664
716
|
|
665
717
|
var toUriEncoding_1 = toUriEncoding;
|
666
718
|
|
667
|
-
function
|
719
|
+
function makeLog(referenceTime) {
|
720
|
+
return function log() {
|
721
|
+
const args = ['[dom-snapshot]', `[+${Date.now() - referenceTime}ms]`].concat(
|
722
|
+
Array.from(arguments),
|
723
|
+
);
|
724
|
+
console.log.apply(console, args);
|
725
|
+
};
|
726
|
+
}
|
727
|
+
|
728
|
+
var log = makeLog;
|
729
|
+
|
730
|
+
const RESOURCE_STORAGE_KEY = '__process_resource';
|
731
|
+
|
732
|
+
function makeSessionCache({log, sessionStorage}) {
|
733
|
+
let sessionStorageCache;
|
734
|
+
try {
|
735
|
+
sessionStorage = sessionStorage || window.sessionStorage;
|
736
|
+
const sessionStorageCacheStr = sessionStorage.getItem(RESOURCE_STORAGE_KEY);
|
737
|
+
sessionStorageCache = sessionStorageCacheStr ? JSON.parse(sessionStorageCacheStr) : {};
|
738
|
+
} catch (ex) {
|
739
|
+
log('error creating session cache', ex);
|
740
|
+
}
|
741
|
+
|
742
|
+
return {
|
743
|
+
getItem,
|
744
|
+
setItem,
|
745
|
+
keys,
|
746
|
+
persist,
|
747
|
+
};
|
748
|
+
|
749
|
+
function getItem(key) {
|
750
|
+
if (sessionStorageCache) {
|
751
|
+
return sessionStorageCache[key];
|
752
|
+
}
|
753
|
+
}
|
754
|
+
|
755
|
+
function setItem(key, value) {
|
756
|
+
if (sessionStorageCache) {
|
757
|
+
log('saving to in-memory sessionStorage, key:', key, 'value:', value);
|
758
|
+
sessionStorageCache[key] = value;
|
759
|
+
}
|
760
|
+
}
|
761
|
+
|
762
|
+
function keys() {
|
763
|
+
if (sessionStorageCache) {
|
764
|
+
return Object.keys(sessionStorageCache);
|
765
|
+
} else {
|
766
|
+
return [];
|
767
|
+
}
|
768
|
+
}
|
769
|
+
|
770
|
+
function persist() {
|
771
|
+
if (sessionStorageCache) {
|
772
|
+
sessionStorage.setItem(RESOURCE_STORAGE_KEY, JSON.stringify(sessionStorageCache));
|
773
|
+
}
|
774
|
+
}
|
775
|
+
}
|
776
|
+
|
777
|
+
var sessionCache = makeSessionCache;
|
778
|
+
|
779
|
+
function processPage(doc = document, {showLogs, useSessionCache} = {}) {
|
780
|
+
const log$$1 = showLogs ? log(Date.now()) : noop;
|
781
|
+
log$$1('processPage start');
|
782
|
+
const sessionCache$$1 = useSessionCache && sessionCache({log: log$$1});
|
668
783
|
const styleSheetCache = {};
|
669
784
|
const extractResourcesFromStyleSheet$$1 = extractResourcesFromStyleSheet({styleSheetCache});
|
670
785
|
const findStyleSheetByUrl$$1 = findStyleSheetByUrl({styleSheetCache});
|
@@ -676,9 +791,12 @@ function __processPageAndPoll() {
|
|
676
791
|
const processResource$$1 = processResource({
|
677
792
|
fetchUrl: fetchUrl_1,
|
678
793
|
findStyleSheetByUrl: findStyleSheetByUrl$$1,
|
794
|
+
getCorsFreeStyleSheet: getCorsFreeStyleSheet_1,
|
679
795
|
extractResourcesFromStyleSheet: extractResourcesFromStyleSheet$$1,
|
680
796
|
extractResourcesFromSvg,
|
681
797
|
absolutizeUrl: absolutizeUrl_1,
|
798
|
+
log: log$$1,
|
799
|
+
sessionCache: sessionCache$$1,
|
682
800
|
});
|
683
801
|
|
684
802
|
const getResourceUrlsAndBlobs$$1 = getResourceUrlsAndBlobs({
|
@@ -686,47 +804,63 @@ function __processPageAndPoll() {
|
|
686
804
|
aggregateResourceUrlsAndBlobs: aggregateResourceUrlsAndBlobs_1,
|
687
805
|
});
|
688
806
|
|
689
|
-
return doProcessPage(doc)
|
807
|
+
return doProcessPage(doc).then(result => {
|
808
|
+
log$$1('processPage end');
|
809
|
+
return result;
|
810
|
+
});
|
690
811
|
|
691
|
-
function doProcessPage(doc,
|
692
|
-
const
|
693
|
-
const {cdt, docRoots, canvasElements, inlineFrames} = domNodesToCdt_1(doc,
|
812
|
+
function doProcessPage(doc, pageUrl = doc.location.href) {
|
813
|
+
const baseUrl = getBaseUrl(doc) || pageUrl;
|
814
|
+
const {cdt, docRoots, canvasElements, inlineFrames} = domNodesToCdt_1(doc, baseUrl);
|
694
815
|
|
695
816
|
const linkUrls = flat_1(docRoots.map(extractLinks_1));
|
696
817
|
const styleTagUrls = flat_1(docRoots.map(extractResourceUrlsFromStyleTags$$1));
|
697
|
-
const absolutizeThisUrl = getAbsolutizeByUrl(
|
698
|
-
const
|
818
|
+
const absolutizeThisUrl = getAbsolutizeByUrl(baseUrl);
|
819
|
+
const urls = uniq_1(
|
699
820
|
Array.from(linkUrls)
|
700
821
|
.concat(Array.from(styleTagUrls))
|
701
822
|
.concat(extractResourceUrlsFromStyleAttrs_1(cdt)),
|
702
823
|
)
|
703
|
-
.map(toUnAnchoredUri_1)
|
704
824
|
.map(toUriEncoding_1)
|
705
825
|
.map(absolutizeThisUrl)
|
826
|
+
.map(toUnAnchoredUri_1)
|
706
827
|
.filter(filterInlineUrlsIfExisting);
|
707
828
|
|
708
|
-
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(docRoots,
|
829
|
+
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1({documents: docRoots, urls}).then(
|
830
|
+
result => {
|
831
|
+
sessionCache$$1 && sessionCache$$1.persist();
|
832
|
+
return result;
|
833
|
+
},
|
834
|
+
);
|
709
835
|
const canvasBlobs = buildCanvasBlobs_1(canvasElements);
|
710
|
-
|
711
836
|
const frameDocs = extractFrames_1(docRoots);
|
712
|
-
|
837
|
+
|
838
|
+
const processFramesPromise = frameDocs.map(f =>
|
839
|
+
doProcessPage(f, f.defaultView.frameElement.src),
|
840
|
+
);
|
713
841
|
const processInlineFramesPromise = inlineFrames.map(({element, url}) =>
|
714
842
|
doProcessPage(element.contentDocument, url),
|
715
843
|
);
|
716
844
|
|
717
|
-
const
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
resourceUrls,
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
845
|
+
const srcAttr =
|
846
|
+
doc.defaultView &&
|
847
|
+
doc.defaultView.frameElement &&
|
848
|
+
doc.defaultView.frameElement.getAttribute('src');
|
849
|
+
|
850
|
+
return Promise.all(
|
851
|
+
[resourceUrlsAndBlobsPromise].concat(processFramesPromise).concat(processInlineFramesPromise),
|
852
|
+
).then(function(resultsWithFrameResults) {
|
853
|
+
const {resourceUrls, blobsObj} = resultsWithFrameResults[0];
|
854
|
+
const framesResults = resultsWithFrameResults.slice(1);
|
855
|
+
return {
|
856
|
+
cdt,
|
857
|
+
url: pageUrl,
|
858
|
+
srcAttr,
|
859
|
+
resourceUrls: resourceUrls.map(url => url.replace(/^blob:/, '')),
|
860
|
+
blobs: blobsObjToArray(blobsObj).concat(canvasBlobs),
|
861
|
+
frames: framesResults,
|
862
|
+
};
|
863
|
+
});
|
730
864
|
}
|
731
865
|
}
|
732
866
|
|
@@ -757,8 +891,8 @@ function __processPageAndPoll() {
|
|
757
891
|
|
758
892
|
var processPage_1 = processPage;
|
759
893
|
|
760
|
-
function processPageAndSerialize(
|
761
|
-
return processPage_1(
|
894
|
+
function processPageAndSerialize() {
|
895
|
+
return processPage_1.apply(this, arguments).then(serializeFrame);
|
762
896
|
}
|
763
897
|
|
764
898
|
function serializeFrame(frame) {
|
data/lib/applitools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eyes_selenium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.15.
|
4
|
+
version: 3.15.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Applitools Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eyes_core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.15.
|
19
|
+
version: 3.15.32
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.15.
|
26
|
+
version: 3.15.32
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: selenium-webdriver
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|