Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@applitools/dom-snapshot

Package Overview
Dependencies
Maintainers
15
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@applitools/dom-snapshot - npm Package Compare versions

Comparing version 1.2.22 to 1.2.23

src/browser/flat.js

75

dist/processPage.js

@@ -1,2 +0,2 @@

// @applitools/dom-snapshot@1.2.22
// @applitools/dom-snapshot@1.2.23
function __processPage() {

@@ -52,3 +52,3 @@ var processPage = (function () {

const domNodes = [
const cdt = [
{

@@ -58,6 +58,7 @@ nodeType: NODE_TYPES.DOCUMENT,

];
domNodes[0].childNodeIndexes = childrenFactory(domNodes, docNode.childNodes);
return domNodes;
const documents = [docNode];
cdt[0].childNodeIndexes = childrenFactory(cdt, documents, docNode.childNodes);
return {cdt, documents};
function childrenFactory(domNodes, elementNodes) {
function childrenFactory(domNodes, documents, elementNodes) {
if (!elementNodes || elementNodes.length === 0) return null;

@@ -67,3 +68,3 @@

elementNodes.forEach(elementNode => {
const index = elementNodeFactory(domNodes, elementNode);
const index = elementNodeFactory(domNodes, documents, elementNode);
if (index !== null) {

@@ -77,3 +78,3 @@ childIndexes.push(index);

function elementNodeFactory(domNodes, elementNode) {
function elementNodeFactory(domNodes, documents, elementNode) {
let node, manualChildNodeIndexes;

@@ -120,3 +121,3 @@ const {nodeType} = elementNode;

(elementNode.childNodes.length
? childrenFactory(domNodes, elementNode.childNodes)
? childrenFactory(domNodes, documents, elementNode.childNodes)
: []),

@@ -126,3 +127,4 @@ };

if (elementNode.shadowRoot) {
node.shadowRootIndex = elementNodeFactory(domNodes, elementNode.shadowRoot);
node.shadowRootIndex = elementNodeFactory(domNodes, documents, elementNode.shadowRoot);
documents.push(elementNode.shadowRoot);
}

@@ -188,4 +190,11 @@

function extractFrames(doc = document) {
return [...doc.querySelectorAll('iframe[src]:not([src=""])')]
function flat(arr) {
return [].concat(...arr);
}
var flat_1 = flat;
function extractFrames(documents = [document]) {
const iframes = flat_1(documents.map(d => [...d.querySelectorAll('iframe[src]:not([src=""])')]));
return iframes
.map(srcEl => {

@@ -231,5 +240,5 @@ try {

function makeGetResourceUrlsAndBlobs({processResource, aggregateResourceUrlsAndBlobs}) {
return function getResourceUrlsAndBlobs(doc, baseUrl, urls) {
return function getResourceUrlsAndBlobs(documents, baseUrl, urls) {
return Promise.all(
urls.map(url => processResource(url, doc, baseUrl, getResourceUrlsAndBlobs)),
urls.map(url => processResource(url, documents, baseUrl, getResourceUrlsAndBlobs)),
).then(resourceUrlsAndBlobsArr => aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr));

@@ -249,3 +258,4 @@ };

const m = url && url.match(/(^[^#]*)/);
return ((m && m[1]) || url).replace(/\?\s*$/, '');
const res = (m && m[1]) || url;
return (res && res.replace(/\?\s*$/, '')) || url;
}

@@ -269,3 +279,3 @@

}) {
return function processResource(absoluteUrl, doc, baseUrl, getResourceUrlsAndBlobs) {
return function processResource(absoluteUrl, documents, baseUrl, getResourceUrlsAndBlobs) {
return cache[absoluteUrl] || (cache[absoluteUrl] = doProcessResource(absoluteUrl));

@@ -290,5 +300,5 @@

if (/text\/css/.test(type)) {
const styleSheet = findStyleSheetByUrl(url, doc);
const styleSheet = findStyleSheetByUrl(url, documents);
if (styleSheet) {
resourceUrls = extractResourcesFromStyleSheet(styleSheet, doc.defaultView);
resourceUrls = extractResourcesFromStyleSheet(styleSheet, documents[0]);
}

@@ -304,3 +314,3 @@ } else if (/image\/svg/.test(type)) {

.filter(filterInlineUrl_1);
result = getResourceUrlsAndBlobs(doc, baseUrl, resourceUrls).then(
result = getResourceUrlsAndBlobs(documents, baseUrl, resourceUrls).then(
({resourceUrls, blobsObj}) => ({

@@ -373,4 +383,8 @@ resourceUrls,

function makeFindStyleSheetByUrl({styleSheetCache}) {
return function findStyleSheetByUrl(url, doc) {
return styleSheetCache[url] || [...doc.styleSheets].find(styleSheet => styleSheet.href === url);
return function findStyleSheetByUrl(url, documents) {
const allStylesheets = flat_1(documents.map(d => [...d.styleSheets]));
return (
styleSheetCache[url] ||
allStylesheets.find(styleSheet => styleSheet.href && toUnAnchoredUri_1(styleSheet.href) === url)
);
};

@@ -394,3 +408,4 @@ }

function makeExtractResourcesFromStyleSheet({styleSheetCache}) {
return function extractResourcesFromStyleSheet(styleSheet, win = window) {
return function extractResourcesFromStyleSheet(styleSheet, doc = document) {
const win = doc.defaultView || doc.ownerDocument.defaultView;
return uniq_1(

@@ -436,7 +451,7 @@ [...(styleSheet.cssRules || [])].reduce((acc, rule) => {

return uniq_1(
[...doc.getElementsByTagName('style')].reduce((resourceUrls, styleEl) => {
[...doc.querySelectorAll('style')].reduce((resourceUrls, styleEl) => {
const styleSheet = [...doc.styleSheets].find(
styleSheet => styleSheet.ownerNode === styleEl,
);
return resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc.defaultView));
return resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc));
}, []),

@@ -503,9 +518,7 @@ );

const cdt = domNodesToCdt_1(doc);
const {cdt, documents} = domNodesToCdt_1(doc);
const links = uniq_1(
extractLinks_1(doc)
.concat(extractResourceUrlsFromStyleAttrs_1(cdt))
.concat(extractResourceUrlsFromStyleTags$$1(doc)),
)
const linkUrls = flat_1(documents.map(extractLinks_1));
const styleTagUrls = flat_1(documents.map(extractResourceUrlsFromStyleTags$$1));
const links = uniq_1([...linkUrls, ...styleTagUrls, ...extractResourceUrlsFromStyleAttrs_1(cdt)])
.map(toUnAnchoredUri_1)

@@ -516,5 +529,5 @@ .map(toUriEncoding_1)

const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(doc, url, links);
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(documents, url, links);
const frameDocs = extractFrames_1(doc);
const frameDocs = extractFrames_1(documents);
const processFramesPromise = frameDocs.map(doProcessPage);

@@ -521,0 +534,0 @@

@@ -1,2 +0,2 @@

// @applitools/dom-snapshot@1.2.22
// @applitools/dom-snapshot@1.2.23
function __processPageAndPoll() {

@@ -104,3 +104,3 @@ var processPageAndPoll = (function () {

const domNodes = [
const cdt = [
{

@@ -110,6 +110,7 @@ nodeType: NODE_TYPES.DOCUMENT,

];
domNodes[0].childNodeIndexes = childrenFactory(domNodes, docNode.childNodes);
return domNodes;
const documents = [docNode];
cdt[0].childNodeIndexes = childrenFactory(cdt, documents, docNode.childNodes);
return {cdt, documents};
function childrenFactory(domNodes, elementNodes) {
function childrenFactory(domNodes, documents, elementNodes) {
if (!elementNodes || elementNodes.length === 0) return null;

@@ -119,3 +120,3 @@

elementNodes.forEach(elementNode => {
const index = elementNodeFactory(domNodes, elementNode);
const index = elementNodeFactory(domNodes, documents, elementNode);
if (index !== null) {

@@ -129,3 +130,3 @@ childIndexes.push(index);

function elementNodeFactory(domNodes, elementNode) {
function elementNodeFactory(domNodes, documents, elementNode) {
let node, manualChildNodeIndexes;

@@ -172,3 +173,3 @@ const {nodeType} = elementNode;

(elementNode.childNodes.length
? childrenFactory(domNodes, elementNode.childNodes)
? childrenFactory(domNodes, documents, elementNode.childNodes)
: []),

@@ -178,3 +179,4 @@ };

if (elementNode.shadowRoot) {
node.shadowRootIndex = elementNodeFactory(domNodes, elementNode.shadowRoot);
node.shadowRootIndex = elementNodeFactory(domNodes, documents, elementNode.shadowRoot);
documents.push(elementNode.shadowRoot);
}

@@ -240,4 +242,11 @@

function extractFrames(doc = document) {
return [...doc.querySelectorAll('iframe[src]:not([src=""])')]
function flat(arr) {
return [].concat(...arr);
}
var flat_1 = flat;
function extractFrames(documents = [document]) {
const iframes = flat_1(documents.map(d => [...d.querySelectorAll('iframe[src]:not([src=""])')]));
return iframes
.map(srcEl => {

@@ -283,5 +292,5 @@ try {

function makeGetResourceUrlsAndBlobs({processResource, aggregateResourceUrlsAndBlobs}) {
return function getResourceUrlsAndBlobs(doc, baseUrl, urls) {
return function getResourceUrlsAndBlobs(documents, baseUrl, urls) {
return Promise.all(
urls.map(url => processResource(url, doc, baseUrl, getResourceUrlsAndBlobs)),
urls.map(url => processResource(url, documents, baseUrl, getResourceUrlsAndBlobs)),
).then(resourceUrlsAndBlobsArr => aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr));

@@ -301,3 +310,4 @@ };

const m = url && url.match(/(^[^#]*)/);
return ((m && m[1]) || url).replace(/\?\s*$/, '');
const res = (m && m[1]) || url;
return (res && res.replace(/\?\s*$/, '')) || url;
}

@@ -321,3 +331,3 @@

}) {
return function processResource(absoluteUrl, doc, baseUrl, getResourceUrlsAndBlobs) {
return function processResource(absoluteUrl, documents, baseUrl, getResourceUrlsAndBlobs) {
return cache[absoluteUrl] || (cache[absoluteUrl] = doProcessResource(absoluteUrl));

@@ -342,5 +352,5 @@

if (/text\/css/.test(type)) {
const styleSheet = findStyleSheetByUrl(url, doc);
const styleSheet = findStyleSheetByUrl(url, documents);
if (styleSheet) {
resourceUrls = extractResourcesFromStyleSheet(styleSheet, doc.defaultView);
resourceUrls = extractResourcesFromStyleSheet(styleSheet, documents[0]);
}

@@ -356,3 +366,3 @@ } else if (/image\/svg/.test(type)) {

.filter(filterInlineUrl_1);
result = getResourceUrlsAndBlobs(doc, baseUrl, resourceUrls).then(
result = getResourceUrlsAndBlobs(documents, baseUrl, resourceUrls).then(
({resourceUrls, blobsObj}) => ({

@@ -425,4 +435,8 @@ resourceUrls,

function makeFindStyleSheetByUrl({styleSheetCache}) {
return function findStyleSheetByUrl(url, doc) {
return styleSheetCache[url] || [...doc.styleSheets].find(styleSheet => styleSheet.href === url);
return function findStyleSheetByUrl(url, documents) {
const allStylesheets = flat_1(documents.map(d => [...d.styleSheets]));
return (
styleSheetCache[url] ||
allStylesheets.find(styleSheet => styleSheet.href && toUnAnchoredUri_1(styleSheet.href) === url)
);
};

@@ -446,3 +460,4 @@ }

function makeExtractResourcesFromStyleSheet({styleSheetCache}) {
return function extractResourcesFromStyleSheet(styleSheet, win = window) {
return function extractResourcesFromStyleSheet(styleSheet, doc = document) {
const win = doc.defaultView || doc.ownerDocument.defaultView;
return uniq_1(

@@ -488,7 +503,7 @@ [...(styleSheet.cssRules || [])].reduce((acc, rule) => {

return uniq_1(
[...doc.getElementsByTagName('style')].reduce((resourceUrls, styleEl) => {
[...doc.querySelectorAll('style')].reduce((resourceUrls, styleEl) => {
const styleSheet = [...doc.styleSheets].find(
styleSheet => styleSheet.ownerNode === styleEl,
);
return resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc.defaultView));
return resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc));
}, []),

@@ -555,9 +570,7 @@ );

const cdt = domNodesToCdt_1(doc);
const {cdt, documents} = domNodesToCdt_1(doc);
const links = uniq_1(
extractLinks_1(doc)
.concat(extractResourceUrlsFromStyleAttrs_1(cdt))
.concat(extractResourceUrlsFromStyleTags$$1(doc)),
)
const linkUrls = flat_1(documents.map(extractLinks_1));
const styleTagUrls = flat_1(documents.map(extractResourceUrlsFromStyleTags$$1));
const links = uniq_1([...linkUrls, ...styleTagUrls, ...extractResourceUrlsFromStyleAttrs_1(cdt)])
.map(toUnAnchoredUri_1)

@@ -568,5 +581,5 @@ .map(toUriEncoding_1)

const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(doc, url, links);
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(documents, url, links);
const frameDocs = extractFrames_1(doc);
const frameDocs = extractFrames_1(documents);
const processFramesPromise = frameDocs.map(doProcessPage);

@@ -573,0 +586,0 @@

@@ -1,2 +0,2 @@

// @applitools/dom-snapshot@1.2.22
// @applitools/dom-snapshot@1.2.23
function __processPageAndSerialize() {

@@ -104,3 +104,3 @@ var processPageAndSerialize = (function () {

const domNodes = [
const cdt = [
{

@@ -110,6 +110,7 @@ nodeType: NODE_TYPES.DOCUMENT,

];
domNodes[0].childNodeIndexes = childrenFactory(domNodes, docNode.childNodes);
return domNodes;
const documents = [docNode];
cdt[0].childNodeIndexes = childrenFactory(cdt, documents, docNode.childNodes);
return {cdt, documents};
function childrenFactory(domNodes, elementNodes) {
function childrenFactory(domNodes, documents, elementNodes) {
if (!elementNodes || elementNodes.length === 0) return null;

@@ -119,3 +120,3 @@

elementNodes.forEach(elementNode => {
const index = elementNodeFactory(domNodes, elementNode);
const index = elementNodeFactory(domNodes, documents, elementNode);
if (index !== null) {

@@ -129,3 +130,3 @@ childIndexes.push(index);

function elementNodeFactory(domNodes, elementNode) {
function elementNodeFactory(domNodes, documents, elementNode) {
let node, manualChildNodeIndexes;

@@ -172,3 +173,3 @@ const {nodeType} = elementNode;

(elementNode.childNodes.length
? childrenFactory(domNodes, elementNode.childNodes)
? childrenFactory(domNodes, documents, elementNode.childNodes)
: []),

@@ -178,3 +179,4 @@ };

if (elementNode.shadowRoot) {
node.shadowRootIndex = elementNodeFactory(domNodes, elementNode.shadowRoot);
node.shadowRootIndex = elementNodeFactory(domNodes, documents, elementNode.shadowRoot);
documents.push(elementNode.shadowRoot);
}

@@ -240,4 +242,11 @@

function extractFrames(doc = document) {
return [...doc.querySelectorAll('iframe[src]:not([src=""])')]
function flat(arr) {
return [].concat(...arr);
}
var flat_1 = flat;
function extractFrames(documents = [document]) {
const iframes = flat_1(documents.map(d => [...d.querySelectorAll('iframe[src]:not([src=""])')]));
return iframes
.map(srcEl => {

@@ -283,5 +292,5 @@ try {

function makeGetResourceUrlsAndBlobs({processResource, aggregateResourceUrlsAndBlobs}) {
return function getResourceUrlsAndBlobs(doc, baseUrl, urls) {
return function getResourceUrlsAndBlobs(documents, baseUrl, urls) {
return Promise.all(
urls.map(url => processResource(url, doc, baseUrl, getResourceUrlsAndBlobs)),
urls.map(url => processResource(url, documents, baseUrl, getResourceUrlsAndBlobs)),
).then(resourceUrlsAndBlobsArr => aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr));

@@ -301,3 +310,4 @@ };

const m = url && url.match(/(^[^#]*)/);
return ((m && m[1]) || url).replace(/\?\s*$/, '');
const res = (m && m[1]) || url;
return (res && res.replace(/\?\s*$/, '')) || url;
}

@@ -321,3 +331,3 @@

}) {
return function processResource(absoluteUrl, doc, baseUrl, getResourceUrlsAndBlobs) {
return function processResource(absoluteUrl, documents, baseUrl, getResourceUrlsAndBlobs) {
return cache[absoluteUrl] || (cache[absoluteUrl] = doProcessResource(absoluteUrl));

@@ -342,5 +352,5 @@

if (/text\/css/.test(type)) {
const styleSheet = findStyleSheetByUrl(url, doc);
const styleSheet = findStyleSheetByUrl(url, documents);
if (styleSheet) {
resourceUrls = extractResourcesFromStyleSheet(styleSheet, doc.defaultView);
resourceUrls = extractResourcesFromStyleSheet(styleSheet, documents[0]);
}

@@ -356,3 +366,3 @@ } else if (/image\/svg/.test(type)) {

.filter(filterInlineUrl_1);
result = getResourceUrlsAndBlobs(doc, baseUrl, resourceUrls).then(
result = getResourceUrlsAndBlobs(documents, baseUrl, resourceUrls).then(
({resourceUrls, blobsObj}) => ({

@@ -425,4 +435,8 @@ resourceUrls,

function makeFindStyleSheetByUrl({styleSheetCache}) {
return function findStyleSheetByUrl(url, doc) {
return styleSheetCache[url] || [...doc.styleSheets].find(styleSheet => styleSheet.href === url);
return function findStyleSheetByUrl(url, documents) {
const allStylesheets = flat_1(documents.map(d => [...d.styleSheets]));
return (
styleSheetCache[url] ||
allStylesheets.find(styleSheet => styleSheet.href && toUnAnchoredUri_1(styleSheet.href) === url)
);
};

@@ -446,3 +460,4 @@ }

function makeExtractResourcesFromStyleSheet({styleSheetCache}) {
return function extractResourcesFromStyleSheet(styleSheet, win = window) {
return function extractResourcesFromStyleSheet(styleSheet, doc = document) {
const win = doc.defaultView || doc.ownerDocument.defaultView;
return uniq_1(

@@ -488,7 +503,7 @@ [...(styleSheet.cssRules || [])].reduce((acc, rule) => {

return uniq_1(
[...doc.getElementsByTagName('style')].reduce((resourceUrls, styleEl) => {
[...doc.querySelectorAll('style')].reduce((resourceUrls, styleEl) => {
const styleSheet = [...doc.styleSheets].find(
styleSheet => styleSheet.ownerNode === styleEl,
);
return resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc.defaultView));
return resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc));
}, []),

@@ -555,9 +570,7 @@ );

const cdt = domNodesToCdt_1(doc);
const {cdt, documents} = domNodesToCdt_1(doc);
const links = uniq_1(
extractLinks_1(doc)
.concat(extractResourceUrlsFromStyleAttrs_1(cdt))
.concat(extractResourceUrlsFromStyleTags$$1(doc)),
)
const linkUrls = flat_1(documents.map(extractLinks_1));
const styleTagUrls = flat_1(documents.map(extractResourceUrlsFromStyleTags$$1));
const links = uniq_1([...linkUrls, ...styleTagUrls, ...extractResourceUrlsFromStyleAttrs_1(cdt)])
.map(toUnAnchoredUri_1)

@@ -568,5 +581,5 @@ .map(toUriEncoding_1)

const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(doc, url, links);
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(documents, url, links);
const frameDocs = extractFrames_1(doc);
const frameDocs = extractFrames_1(documents);
const processFramesPromise = frameDocs.map(doProcessPage);

@@ -573,0 +586,0 @@

@@ -49,3 +49,3 @@ 'use strict';

const domNodes = [
const cdt = [
{

@@ -55,6 +55,7 @@ nodeType: NODE_TYPES.DOCUMENT,

];
domNodes[0].childNodeIndexes = childrenFactory(domNodes, docNode.childNodes);
return domNodes;
const documents = [docNode];
cdt[0].childNodeIndexes = childrenFactory(cdt, documents, docNode.childNodes);
return {cdt, documents};
function childrenFactory(domNodes, elementNodes) {
function childrenFactory(domNodes, documents, elementNodes) {
if (!elementNodes || elementNodes.length === 0) return null;

@@ -64,3 +65,3 @@

elementNodes.forEach(elementNode => {
const index = elementNodeFactory(domNodes, elementNode);
const index = elementNodeFactory(domNodes, documents, elementNode);
if (index !== null) {

@@ -74,3 +75,3 @@ childIndexes.push(index);

function elementNodeFactory(domNodes, elementNode) {
function elementNodeFactory(domNodes, documents, elementNode) {
let node, manualChildNodeIndexes;

@@ -117,3 +118,3 @@ const {nodeType} = elementNode;

(elementNode.childNodes.length
? childrenFactory(domNodes, elementNode.childNodes)
? childrenFactory(domNodes, documents, elementNode.childNodes)
: []),

@@ -123,3 +124,4 @@ };

if (elementNode.shadowRoot) {
node.shadowRootIndex = elementNodeFactory(domNodes, elementNode.shadowRoot);
node.shadowRootIndex = elementNodeFactory(domNodes, documents, elementNode.shadowRoot);
documents.push(elementNode.shadowRoot);
}

@@ -185,4 +187,11 @@

function extractFrames(doc = document) {
return [...doc.querySelectorAll('iframe[src]:not([src=""])')]
function flat(arr) {
return [].concat(...arr);
}
var flat_1 = flat;
function extractFrames(documents = [document]) {
const iframes = flat_1(documents.map(d => [...d.querySelectorAll('iframe[src]:not([src=""])')]));
return iframes
.map(srcEl => {

@@ -228,5 +237,5 @@ try {

function makeGetResourceUrlsAndBlobs({processResource, aggregateResourceUrlsAndBlobs}) {
return function getResourceUrlsAndBlobs(doc, baseUrl, urls) {
return function getResourceUrlsAndBlobs(documents, baseUrl, urls) {
return Promise.all(
urls.map(url => processResource(url, doc, baseUrl, getResourceUrlsAndBlobs)),
urls.map(url => processResource(url, documents, baseUrl, getResourceUrlsAndBlobs)),
).then(resourceUrlsAndBlobsArr => aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr));

@@ -246,3 +255,4 @@ };

const m = url && url.match(/(^[^#]*)/);
return ((m && m[1]) || url).replace(/\?\s*$/, '');
const res = (m && m[1]) || url;
return (res && res.replace(/\?\s*$/, '')) || url;
}

@@ -266,3 +276,3 @@

}) {
return function processResource(absoluteUrl, doc, baseUrl, getResourceUrlsAndBlobs) {
return function processResource(absoluteUrl, documents, baseUrl, getResourceUrlsAndBlobs) {
return cache[absoluteUrl] || (cache[absoluteUrl] = doProcessResource(absoluteUrl));

@@ -287,5 +297,5 @@

if (/text\/css/.test(type)) {
const styleSheet = findStyleSheetByUrl(url, doc);
const styleSheet = findStyleSheetByUrl(url, documents);
if (styleSheet) {
resourceUrls = extractResourcesFromStyleSheet(styleSheet, doc.defaultView);
resourceUrls = extractResourcesFromStyleSheet(styleSheet, documents[0]);
}

@@ -301,3 +311,3 @@ } else if (/image\/svg/.test(type)) {

.filter(filterInlineUrl_1);
result = getResourceUrlsAndBlobs(doc, baseUrl, resourceUrls).then(
result = getResourceUrlsAndBlobs(documents, baseUrl, resourceUrls).then(
({resourceUrls, blobsObj}) => ({

@@ -370,4 +380,8 @@ resourceUrls,

function makeFindStyleSheetByUrl({styleSheetCache}) {
return function findStyleSheetByUrl(url, doc) {
return styleSheetCache[url] || [...doc.styleSheets].find(styleSheet => styleSheet.href === url);
return function findStyleSheetByUrl(url, documents) {
const allStylesheets = flat_1(documents.map(d => [...d.styleSheets]));
return (
styleSheetCache[url] ||
allStylesheets.find(styleSheet => styleSheet.href && toUnAnchoredUri_1(styleSheet.href) === url)
);
};

@@ -391,3 +405,4 @@ }

function makeExtractResourcesFromStyleSheet({styleSheetCache}) {
return function extractResourcesFromStyleSheet(styleSheet, win = window) {
return function extractResourcesFromStyleSheet(styleSheet, doc = document) {
const win = doc.defaultView || doc.ownerDocument.defaultView;
return uniq_1(

@@ -433,7 +448,7 @@ [...(styleSheet.cssRules || [])].reduce((acc, rule) => {

return uniq_1(
[...doc.getElementsByTagName('style')].reduce((resourceUrls, styleEl) => {
[...doc.querySelectorAll('style')].reduce((resourceUrls, styleEl) => {
const styleSheet = [...doc.styleSheets].find(
styleSheet => styleSheet.ownerNode === styleEl,
);
return resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc.defaultView));
return resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc));
}, []),

@@ -500,9 +515,7 @@ );

const cdt = domNodesToCdt_1(doc);
const {cdt, documents} = domNodesToCdt_1(doc);
const links = uniq_1(
extractLinks_1(doc)
.concat(extractResourceUrlsFromStyleAttrs_1(cdt))
.concat(extractResourceUrlsFromStyleTags$$1(doc)),
)
const linkUrls = flat_1(documents.map(extractLinks_1));
const styleTagUrls = flat_1(documents.map(extractResourceUrlsFromStyleTags$$1));
const links = uniq_1([...linkUrls, ...styleTagUrls, ...extractResourceUrlsFromStyleAttrs_1(cdt)])
.map(toUnAnchoredUri_1)

@@ -513,5 +526,5 @@ .map(toUriEncoding_1)

const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(doc, url, links);
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(documents, url, links);
const frameDocs = extractFrames_1(doc);
const frameDocs = extractFrames_1(documents);
const processFramesPromise = frameDocs.map(doProcessPage);

@@ -518,0 +531,0 @@

{
"name": "@applitools/dom-snapshot",
"version": "1.2.22",
"version": "1.2.23",
"main": "index.js",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -19,2 +19,6 @@ # dom-snapshot

- `getProcessPageAndSerializeScript`
- `getProcessPageAndPollScript`
- `makeExtractResourcesFromSvg`
- `toUriEncoding`
- `toUnAnchoredUri`

@@ -21,0 +25,0 @@ These async functions return a string with a function that can be sent to the browser for evaluation. It doesn't immediately invoke the function, so the sender should wrap it as an IIFE. For example:

@@ -13,3 +13,3 @@ /* eslint-disable no-use-before-define */

const domNodes = [
const cdt = [
{

@@ -19,6 +19,7 @@ nodeType: NODE_TYPES.DOCUMENT,

];
domNodes[0].childNodeIndexes = childrenFactory(domNodes, docNode.childNodes);
return domNodes;
const documents = [docNode];
cdt[0].childNodeIndexes = childrenFactory(cdt, documents, docNode.childNodes);
return {cdt, documents};
function childrenFactory(domNodes, elementNodes) {
function childrenFactory(domNodes, documents, elementNodes) {
if (!elementNodes || elementNodes.length === 0) return null;

@@ -28,3 +29,3 @@

elementNodes.forEach(elementNode => {
const index = elementNodeFactory(domNodes, elementNode);
const index = elementNodeFactory(domNodes, documents, elementNode);
if (index !== null) {

@@ -38,3 +39,3 @@ childIndexes.push(index);

function elementNodeFactory(domNodes, elementNode) {
function elementNodeFactory(domNodes, documents, elementNode) {
let node, manualChildNodeIndexes;

@@ -81,3 +82,3 @@ const {nodeType} = elementNode;

(elementNode.childNodes.length
? childrenFactory(domNodes, elementNode.childNodes)
? childrenFactory(domNodes, documents, elementNode.childNodes)
: []),

@@ -87,3 +88,4 @@ };

if (elementNode.shadowRoot) {
node.shadowRootIndex = elementNodeFactory(domNodes, elementNode.shadowRoot);
node.shadowRootIndex = elementNodeFactory(domNodes, documents, elementNode.shadowRoot);
documents.push(elementNode.shadowRoot);
}

@@ -90,0 +92,0 @@

'use strict';
const flat = require('./flat');
function extractFrames(doc = document) {
return [...doc.querySelectorAll('iframe[src]:not([src=""])')]
function extractFrames(documents = [document]) {
const iframes = flat(documents.map(d => [...d.querySelectorAll('iframe[src]:not([src=""])')]));
return iframes
.map(srcEl => {

@@ -6,0 +8,0 @@ try {

@@ -6,3 +6,4 @@ 'use strict';

function makeExtractResourcesFromStyleSheet({styleSheetCache}) {
return function extractResourcesFromStyleSheet(styleSheet, win = window) {
return function extractResourcesFromStyleSheet(styleSheet, doc = document) {
const win = doc.defaultView || doc.ownerDocument.defaultView;
return uniq(

@@ -9,0 +10,0 @@ [...(styleSheet.cssRules || [])].reduce((acc, rule) => {

@@ -7,7 +7,7 @@ 'use strict';

return uniq(
[...doc.getElementsByTagName('style')].reduce((resourceUrls, styleEl) => {
[...doc.querySelectorAll('style')].reduce((resourceUrls, styleEl) => {
const styleSheet = [...doc.styleSheets].find(
styleSheet => styleSheet.ownerNode === styleEl,
);
return resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc.defaultView));
return resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc));
}, []),

@@ -14,0 +14,0 @@ );

'use strict';
const flat = require('./flat');
const toUnAnchoredUri = require('./toUnAnchoredUri');
function makeFindStyleSheetByUrl({styleSheetCache}) {
return function findStyleSheetByUrl(url, doc) {
return styleSheetCache[url] || [...doc.styleSheets].find(styleSheet => styleSheet.href === url);
return function findStyleSheetByUrl(url, documents) {
const allStylesheets = flat(documents.map(d => [...d.styleSheets]));
return (
styleSheetCache[url] ||
allStylesheets.find(styleSheet => styleSheet.href && toUnAnchoredUri(styleSheet.href) === url)
);
};

@@ -7,0 +13,0 @@ }

'use strict';
function makeGetResourceUrlsAndBlobs({processResource, aggregateResourceUrlsAndBlobs}) {
return function getResourceUrlsAndBlobs(doc, baseUrl, urls) {
return function getResourceUrlsAndBlobs(documents, baseUrl, urls) {
return Promise.all(
urls.map(url => processResource(url, doc, baseUrl, getResourceUrlsAndBlobs)),
urls.map(url => processResource(url, documents, baseUrl, getResourceUrlsAndBlobs)),
).then(resourceUrlsAndBlobsArr => aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr));

@@ -8,0 +8,0 @@ };

@@ -18,2 +18,3 @@ 'use strict';

const uniq = require('./uniq');
const flat = require('./flat');
const filterInlineUrl = require('./filterInlineUrl');

@@ -51,9 +52,7 @@ const isSameOrigin = require('./isSameOrigin');

const cdt = domNodesToCdt(doc);
const {cdt, documents} = domNodesToCdt(doc);
const links = uniq(
extractLinks(doc)
.concat(extractResourceUrlsFromStyleAttrs(cdt))
.concat(extractResourceUrlsFromStyleTags(doc)),
)
const linkUrls = flat(documents.map(extractLinks));
const styleTagUrls = flat(documents.map(extractResourceUrlsFromStyleTags));
const links = uniq([...linkUrls, ...styleTagUrls, ...extractResourceUrlsFromStyleAttrs(cdt)])
.map(toUnAnchoredUri)

@@ -64,5 +63,5 @@ .map(toUriEncoding)

const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs(doc, url, links);
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs(documents, url, links);
const frameDocs = extractFrames(doc);
const frameDocs = extractFrames(documents);
const processFramesPromise = frameDocs.map(doProcessPage);

@@ -69,0 +68,0 @@

@@ -14,3 +14,3 @@ 'use strict';

}) {
return function processResource(absoluteUrl, doc, baseUrl, getResourceUrlsAndBlobs) {
return function processResource(absoluteUrl, documents, baseUrl, getResourceUrlsAndBlobs) {
return cache[absoluteUrl] || (cache[absoluteUrl] = doProcessResource(absoluteUrl));

@@ -35,5 +35,5 @@

if (/text\/css/.test(type)) {
const styleSheet = findStyleSheetByUrl(url, doc);
const styleSheet = findStyleSheetByUrl(url, documents);
if (styleSheet) {
resourceUrls = extractResourcesFromStyleSheet(styleSheet, doc.defaultView);
resourceUrls = extractResourcesFromStyleSheet(styleSheet, documents[0]);
}

@@ -49,3 +49,3 @@ } else if (/image\/svg/.test(type)) {

.filter(filterInlineUrl);
result = getResourceUrlsAndBlobs(doc, baseUrl, resourceUrls).then(
result = getResourceUrlsAndBlobs(documents, baseUrl, resourceUrls).then(
({resourceUrls, blobsObj}) => ({

@@ -52,0 +52,0 @@ resourceUrls,

@@ -5,5 +5,6 @@ 'use strict';

const m = url && url.match(/(^[^#]*)/);
return ((m && m[1]) || url).replace(/\?\s*$/, '');
const res = (m && m[1]) || url;
return (res && res.replace(/\?\s*$/, '')) || url;
}
module.exports = toUnAnchoredUri;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc