@applitools/dom-snapshot
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -162,3 +162,3 @@ | ||
function aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr, initialValue) { | ||
function aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr) { | ||
return resourceUrlsAndBlobsArr.reduce( | ||
@@ -169,3 +169,3 @@ ({resourceUrls: allResourceUrls, blobsObj: allBlobsObj}, {resourceUrls, blobsObj}) => ({ | ||
}), | ||
initialValue, | ||
{resourceUrls: [], blobsObj: {}}, | ||
); | ||
@@ -176,44 +176,7 @@ } | ||
function isSameOrigin(url, baseUrl) { | ||
const blobOrData = /^(blob|data):/; | ||
if (blobOrData.test(url)) return true; | ||
if (blobOrData.test(baseUrl)) return false; | ||
const {origin} = new URL(url, baseUrl); | ||
const {origin: baseOrigin} = new URL(baseUrl); | ||
return origin === baseOrigin; | ||
} | ||
var isSameOrigin_1 = isSameOrigin; | ||
function splitOnOrigin(urls, baseUrl) { | ||
const result = urls.reduce( | ||
({internalUrls, externalUrls}, url) => { | ||
if (isSameOrigin_1(url, baseUrl)) { | ||
internalUrls.push(url); | ||
} else { | ||
externalUrls.push(url); | ||
} | ||
return {internalUrls, externalUrls}; | ||
}, | ||
{externalUrls: [], internalUrls: []}, | ||
); | ||
return result; | ||
} | ||
var splitOnOrigin_1 = splitOnOrigin; | ||
function makeGetResourceUrlsAndBlobs({processResource, aggregateResourceUrlsAndBlobs}) { | ||
return function getResourceUrlsAndBlobs(doc, baseUrl, absoluteUrls) { | ||
const {externalUrls, internalUrls} = splitOnOrigin_1(absoluteUrls, baseUrl); | ||
return function getResourceUrlsAndBlobs(doc, baseUrl, urls) { | ||
return Promise.all( | ||
internalUrls.map(url => | ||
processResource(url, doc, getResourceUrlsAndBlobs.bind(null, doc, baseUrl)), | ||
), | ||
).then(resourceUrlsAndBlobsArr => | ||
aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr, { | ||
resourceUrls: externalUrls, | ||
blobsObj: {}, | ||
}), | ||
); | ||
urls.map(url => processResource(url, doc, baseUrl, getResourceUrlsAndBlobs.bind(null, doc))), | ||
).then(resourceUrlsAndBlobsArr => aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr)); | ||
}; | ||
@@ -240,5 +203,6 @@ } | ||
extractResourcesFromStyleSheet, | ||
isSameOrigin, | ||
cache = {}, | ||
}) { | ||
return function processResource(absoluteUrl, doc, getResourceUrlsAndBlobs) { | ||
return function processResource(absoluteUrl, doc, baseUrl, getResourceUrlsAndBlobs) { | ||
return cache[absoluteUrl] || (cache[absoluteUrl] = doProcessResource(absoluteUrl)); | ||
@@ -248,3 +212,13 @@ | ||
return fetchUrl(url) | ||
.then(({url, type, value}) => { | ||
.catch(e => { | ||
if (probablyCORS(e, url)) { | ||
return {probablyCORS: true, url}; | ||
} else { | ||
throw e; | ||
} | ||
}) | ||
.then(({url, type, value, probablyCORS}) => { | ||
if (probablyCORS) { | ||
return {resourceUrls: [url]}; | ||
} | ||
const result = {blobsObj: {[url]: {type, value}}}; | ||
@@ -259,6 +233,8 @@ if (/text\/css/.test(type)) { | ||
.filter(filterInlineUrl_1); | ||
return getResourceUrlsAndBlobs(resourceUrls).then(({resourceUrls, blobsObj}) => ({ | ||
resourceUrls, | ||
blobsObj: Object.assign(blobsObj, {[url]: {type, value}}), | ||
})); | ||
return getResourceUrlsAndBlobs(baseUrl, resourceUrls).then( | ||
({resourceUrls, blobsObj}) => ({ | ||
resourceUrls, | ||
blobsObj: Object.assign(blobsObj, {[url]: {type, value}}), | ||
}), | ||
); | ||
} else { | ||
@@ -269,6 +245,12 @@ return result; | ||
.catch(err => { | ||
console.log('[dom-capture] error while fetching', url, err); | ||
console.log('[dom-snapshot] error while fetching', url, err); | ||
return {}; | ||
}); | ||
} | ||
function probablyCORS(err, url) { | ||
const msgCORS = err.message && err.message.includes('Failed to fetch'); | ||
const nameCORS = err.name && err.name.includes('TypeError'); | ||
return msgCORS && nameCORS && !isSameOrigin(url, baseUrl); | ||
} | ||
}; | ||
@@ -368,2 +350,14 @@ } | ||
function isSameOrigin(url, baseUrl) { | ||
const blobOrData = /^(blob|data):/; | ||
if (blobOrData.test(url)) return true; | ||
if (blobOrData.test(baseUrl)) return false; | ||
const {origin} = new URL(url, baseUrl); | ||
const {origin: baseOrigin} = new URL(baseUrl); | ||
return origin === baseOrigin; | ||
} | ||
var isSameOrigin_1 = isSameOrigin; | ||
function processPage(doc = document) { | ||
@@ -378,2 +372,3 @@ const styleSheetCache = {}; | ||
absolutizeUrl: absolutizeUrl_1, | ||
isSameOrigin: isSameOrigin_1, | ||
}); | ||
@@ -380,0 +375,0 @@ |
@@ -214,3 +214,3 @@ | ||
function aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr, initialValue) { | ||
function aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr) { | ||
return resourceUrlsAndBlobsArr.reduce( | ||
@@ -221,3 +221,3 @@ ({resourceUrls: allResourceUrls, blobsObj: allBlobsObj}, {resourceUrls, blobsObj}) => ({ | ||
}), | ||
initialValue, | ||
{resourceUrls: [], blobsObj: {}}, | ||
); | ||
@@ -228,44 +228,7 @@ } | ||
function isSameOrigin(url, baseUrl) { | ||
const blobOrData = /^(blob|data):/; | ||
if (blobOrData.test(url)) return true; | ||
if (blobOrData.test(baseUrl)) return false; | ||
const {origin} = new URL(url, baseUrl); | ||
const {origin: baseOrigin} = new URL(baseUrl); | ||
return origin === baseOrigin; | ||
} | ||
var isSameOrigin_1 = isSameOrigin; | ||
function splitOnOrigin(urls, baseUrl) { | ||
const result = urls.reduce( | ||
({internalUrls, externalUrls}, url) => { | ||
if (isSameOrigin_1(url, baseUrl)) { | ||
internalUrls.push(url); | ||
} else { | ||
externalUrls.push(url); | ||
} | ||
return {internalUrls, externalUrls}; | ||
}, | ||
{externalUrls: [], internalUrls: []}, | ||
); | ||
return result; | ||
} | ||
var splitOnOrigin_1 = splitOnOrigin; | ||
function makeGetResourceUrlsAndBlobs({processResource, aggregateResourceUrlsAndBlobs}) { | ||
return function getResourceUrlsAndBlobs(doc, baseUrl, absoluteUrls) { | ||
const {externalUrls, internalUrls} = splitOnOrigin_1(absoluteUrls, baseUrl); | ||
return function getResourceUrlsAndBlobs(doc, baseUrl, urls) { | ||
return Promise.all( | ||
internalUrls.map(url => | ||
processResource(url, doc, getResourceUrlsAndBlobs.bind(null, doc, baseUrl)), | ||
), | ||
).then(resourceUrlsAndBlobsArr => | ||
aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr, { | ||
resourceUrls: externalUrls, | ||
blobsObj: {}, | ||
}), | ||
); | ||
urls.map(url => processResource(url, doc, baseUrl, getResourceUrlsAndBlobs.bind(null, doc))), | ||
).then(resourceUrlsAndBlobsArr => aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr)); | ||
}; | ||
@@ -292,5 +255,6 @@ } | ||
extractResourcesFromStyleSheet, | ||
isSameOrigin, | ||
cache = {}, | ||
}) { | ||
return function processResource(absoluteUrl, doc, getResourceUrlsAndBlobs) { | ||
return function processResource(absoluteUrl, doc, baseUrl, getResourceUrlsAndBlobs) { | ||
return cache[absoluteUrl] || (cache[absoluteUrl] = doProcessResource(absoluteUrl)); | ||
@@ -300,3 +264,13 @@ | ||
return fetchUrl(url) | ||
.then(({url, type, value}) => { | ||
.catch(e => { | ||
if (probablyCORS(e, url)) { | ||
return {probablyCORS: true, url}; | ||
} else { | ||
throw e; | ||
} | ||
}) | ||
.then(({url, type, value, probablyCORS}) => { | ||
if (probablyCORS) { | ||
return {resourceUrls: [url]}; | ||
} | ||
const result = {blobsObj: {[url]: {type, value}}}; | ||
@@ -311,6 +285,8 @@ if (/text\/css/.test(type)) { | ||
.filter(filterInlineUrl_1); | ||
return getResourceUrlsAndBlobs(resourceUrls).then(({resourceUrls, blobsObj}) => ({ | ||
resourceUrls, | ||
blobsObj: Object.assign(blobsObj, {[url]: {type, value}}), | ||
})); | ||
return getResourceUrlsAndBlobs(baseUrl, resourceUrls).then( | ||
({resourceUrls, blobsObj}) => ({ | ||
resourceUrls, | ||
blobsObj: Object.assign(blobsObj, {[url]: {type, value}}), | ||
}), | ||
); | ||
} else { | ||
@@ -321,6 +297,12 @@ return result; | ||
.catch(err => { | ||
console.log('[dom-capture] error while fetching', url, err); | ||
console.log('[dom-snapshot] error while fetching', url, err); | ||
return {}; | ||
}); | ||
} | ||
function probablyCORS(err, url) { | ||
const msgCORS = err.message && err.message.includes('Failed to fetch'); | ||
const nameCORS = err.name && err.name.includes('TypeError'); | ||
return msgCORS && nameCORS && !isSameOrigin(url, baseUrl); | ||
} | ||
}; | ||
@@ -420,2 +402,14 @@ } | ||
function isSameOrigin(url, baseUrl) { | ||
const blobOrData = /^(blob|data):/; | ||
if (blobOrData.test(url)) return true; | ||
if (blobOrData.test(baseUrl)) return false; | ||
const {origin} = new URL(url, baseUrl); | ||
const {origin: baseOrigin} = new URL(baseUrl); | ||
return origin === baseOrigin; | ||
} | ||
var isSameOrigin_1 = isSameOrigin; | ||
function processPage(doc = document) { | ||
@@ -430,2 +424,3 @@ const styleSheetCache = {}; | ||
absolutizeUrl: absolutizeUrl_1, | ||
isSameOrigin: isSameOrigin_1, | ||
}); | ||
@@ -432,0 +427,0 @@ |
{ | ||
"name": "@applitools/dom-snapshot", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "index.js", | ||
@@ -26,2 +26,3 @@ "license": "MIT", | ||
"chai": "^4.2.0", | ||
"cors": "^2.8.5", | ||
"cssom": "git+https://github.com/amitzur/CSSOM.git#925260ff2c8f8387cf76df4d5776a06044a644c8", | ||
@@ -36,3 +37,3 @@ "eslint": "5.7.0", | ||
"node-fetch": "^2.3.0", | ||
"prettier": "^1.15.3", | ||
"prettier": "^1.16.0", | ||
"puppeteer": "1.9.0", | ||
@@ -46,4 +47,4 @@ "rollup": "^0.66.6", | ||
"dependencies": { | ||
"@applitools/functional-commons": "^1.0.27" | ||
"@applitools/functional-commons": "^1.0.33" | ||
} | ||
} |
@@ -22,3 +22,3 @@ { | ||
"semi": true, | ||
"parser": "babylon", | ||
"parser": "babel", | ||
"printWidth": 100, | ||
@@ -25,0 +25,0 @@ "singleQuote": true, |
'use strict'; | ||
const uniq = require('./uniq'); | ||
function aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr, initialValue) { | ||
function aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr) { | ||
return resourceUrlsAndBlobsArr.reduce( | ||
@@ -10,3 +10,3 @@ ({resourceUrls: allResourceUrls, blobsObj: allBlobsObj}, {resourceUrls, blobsObj}) => ({ | ||
}), | ||
initialValue, | ||
{resourceUrls: [], blobsObj: {}}, | ||
); | ||
@@ -13,0 +13,0 @@ } |
'use strict'; | ||
const splitOnOrigin = require('./splitOnOrigin'); | ||
function makeGetResourceUrlsAndBlobs({processResource, aggregateResourceUrlsAndBlobs}) { | ||
return function getResourceUrlsAndBlobs(doc, baseUrl, absoluteUrls) { | ||
const {externalUrls, internalUrls} = splitOnOrigin(absoluteUrls, baseUrl); | ||
return function getResourceUrlsAndBlobs(doc, baseUrl, urls) { | ||
return Promise.all( | ||
internalUrls.map(url => | ||
processResource(url, doc, getResourceUrlsAndBlobs.bind(null, doc, baseUrl)), | ||
), | ||
).then(resourceUrlsAndBlobsArr => | ||
aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr, { | ||
resourceUrls: externalUrls, | ||
blobsObj: {}, | ||
}), | ||
); | ||
urls.map(url => processResource(url, doc, baseUrl, getResourceUrlsAndBlobs.bind(null, doc))), | ||
).then(resourceUrlsAndBlobsArr => aggregateResourceUrlsAndBlobs(resourceUrlsAndBlobsArr)); | ||
}; | ||
@@ -18,0 +9,0 @@ } |
@@ -16,2 +16,3 @@ 'use strict'; | ||
const filterInlineUrl = require('./filterInlineUrl'); | ||
const isSameOrigin = require('./isSameOrigin'); | ||
@@ -27,2 +28,3 @@ function processPage(doc = document) { | ||
absolutizeUrl, | ||
isSameOrigin, | ||
}); | ||
@@ -29,0 +31,0 @@ |
@@ -9,5 +9,6 @@ 'use strict'; | ||
extractResourcesFromStyleSheet, | ||
isSameOrigin, | ||
cache = {}, | ||
}) { | ||
return function processResource(absoluteUrl, doc, getResourceUrlsAndBlobs) { | ||
return function processResource(absoluteUrl, doc, baseUrl, getResourceUrlsAndBlobs) { | ||
return cache[absoluteUrl] || (cache[absoluteUrl] = doProcessResource(absoluteUrl)); | ||
@@ -17,3 +18,13 @@ | ||
return fetchUrl(url) | ||
.then(({url, type, value}) => { | ||
.catch(e => { | ||
if (probablyCORS(e, url)) { | ||
return {probablyCORS: true, url}; | ||
} else { | ||
throw e; | ||
} | ||
}) | ||
.then(({url, type, value, probablyCORS}) => { | ||
if (probablyCORS) { | ||
return {resourceUrls: [url]}; | ||
} | ||
const result = {blobsObj: {[url]: {type, value}}}; | ||
@@ -28,6 +39,8 @@ if (/text\/css/.test(type)) { | ||
.filter(filterInlineUrl); | ||
return getResourceUrlsAndBlobs(resourceUrls).then(({resourceUrls, blobsObj}) => ({ | ||
resourceUrls, | ||
blobsObj: Object.assign(blobsObj, {[url]: {type, value}}), | ||
})); | ||
return getResourceUrlsAndBlobs(baseUrl, resourceUrls).then( | ||
({resourceUrls, blobsObj}) => ({ | ||
resourceUrls, | ||
blobsObj: Object.assign(blobsObj, {[url]: {type, value}}), | ||
}), | ||
); | ||
} else { | ||
@@ -42,2 +55,8 @@ return result; | ||
} | ||
function probablyCORS(err, url) { | ||
const msgCORS = err.message && err.message.includes('Failed to fetch'); | ||
const nameCORS = err.name && err.name.includes('TypeError'); | ||
return msgCORS && nameCORS && !isSameOrigin(url, baseUrl); | ||
} | ||
}; | ||
@@ -44,0 +63,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52501
19
27
1336
4