@applitools/dom-capture
Advanced tools
Comparing version 3.3.2 to 3.3.3
function(props={"styleProps":["background-repeat","background-origin","background-position","background-color","background-image","background-size","border-width","border-color","border-style","color","display","font-size","line-height","margin","opacity","overflow","padding","visibility"],"rectProps":["width","height","top","left"],"ignoredTagNames":["HEAD","SCRIPT"]}, doc=document, {returnCaptureAsString = false} = {}) { | ||
function(props={"styleProps":["background-repeat","background-origin","background-position","background-color","background-image","background-size","border-width","border-color","border-style","color","display","font-size","line-height","margin","opacity","overflow","padding","visibility"],"rectProps":["width","height","top","left"],"ignoredTagNames":["HEAD","SCRIPT"]}, doc=document, {returnCaptureAsString = false, returnStringSectionSize = undefined, sectionGlobalVarName} = {}) { | ||
var captureDom = (function () { | ||
@@ -184,2 +184,16 @@ 'use strict'; | ||
function splitStringIntoSections(str, sectionLength) { | ||
const numberOfSections = Math.ceil(str.length / sectionLength); | ||
const sections = Array(numberOfSections); | ||
for (let i = 0; i < numberOfSections; ++i) { | ||
sections[i] = str.slice(i * sectionLength, (i + 1) * sectionLength); | ||
} | ||
return sections; | ||
} | ||
var splitStringIntoSections_1 = splitStringIntoSections; | ||
// any changes to function parameters needs to also be copied to `wrapCaptureDom.js` | ||
@@ -189,3 +203,3 @@ async function captureFrame( | ||
doc = document, | ||
{returnCaptureAsString = false} = {}, | ||
{returnCaptureAsString = false, returnStringSectionSize = undefined, sectionGlobalVarName} = {}, | ||
) { | ||
@@ -250,3 +264,9 @@ const NODE_TYPES = { | ||
.reduce((obj, attr) => { | ||
obj[attr.key] = attr.value; | ||
const {key, value} = attr; | ||
obj[key] = | ||
key === 'src' || key === 'href' || key === 'class' || key === 'style' | ||
? value | ||
: value.slice(0, 100) + (value.length > 100 ? '...' : ''); | ||
return obj; | ||
@@ -288,2 +308,19 @@ }, {}); | ||
if (returnCaptureAsString) { | ||
if (returnStringSectionSize) { | ||
if (!sectionGlobalVarName) | ||
throw new Error( | ||
'if you want to return sections, specify global var name in `sectionGlobalVarName`', | ||
); | ||
window[sectionGlobalVarName] = splitStringIntoSections_1( | ||
JSON.stringify(ret), | ||
returnStringSectionSize, | ||
); | ||
return window[sectionGlobalVarName].length; | ||
} | ||
} else { | ||
return ret; | ||
} | ||
return returnCaptureAsString ? JSON.stringify(ret) : ret; | ||
@@ -298,3 +335,3 @@ } | ||
return captureDom(props, doc, {returnCaptureAsString}); | ||
return captureDom(props, doc, {returnCaptureAsString, returnStringSectionSize, sectionGlobalVarName}); | ||
} |
{ | ||
"name": "@applitools/dom-capture", | ||
"version": "3.3.2", | ||
"version": "3.3.3", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -7,2 +7,3 @@ /* global window, document */ | ||
const getImageSizes = require('./getImageSizes'); | ||
const splitStringIntoSections = require('./splitStringIntoSections'); | ||
@@ -13,3 +14,3 @@ // any changes to function parameters needs to also be copied to `wrapCaptureDom.js` | ||
doc = document, | ||
{returnCaptureAsString = false} = {}, | ||
{returnCaptureAsString = false, returnStringSectionSize = undefined, sectionGlobalVarName} = {}, | ||
) { | ||
@@ -74,3 +75,9 @@ const NODE_TYPES = { | ||
.reduce((obj, attr) => { | ||
obj[attr.key] = attr.value; | ||
const {key, value} = attr; | ||
obj[key] = | ||
key === 'src' || key === 'href' || key === 'class' || key === 'style' | ||
? value | ||
: value.slice(0, 100) + (value.length > 100 ? '...' : ''); | ||
return obj; | ||
@@ -112,2 +119,19 @@ }, {}); | ||
if (returnCaptureAsString) { | ||
if (returnStringSectionSize) { | ||
if (!sectionGlobalVarName) | ||
throw new Error( | ||
'if you want to return sections, specify global var name in `sectionGlobalVarName`', | ||
); | ||
window[sectionGlobalVarName] = splitStringIntoSections( | ||
JSON.stringify(ret), | ||
returnStringSectionSize, | ||
); | ||
return window[sectionGlobalVarName].length; | ||
} | ||
} else { | ||
return ret; | ||
} | ||
return returnCaptureAsString ? JSON.stringify(ret) : ret; | ||
@@ -114,0 +138,0 @@ } |
@@ -11,4 +11,2 @@ const defaultDomProps = require('./defaultDomProps'); | ||
if (tagName === 'IFRAME' && domNode.childNodes.length === 0) { | ||
const src = domNode.attributes ? domNode.attributes.src : ''; | ||
console.log(`getting iframe content for ${xpathTrail}, src=${src}`); | ||
domNode.childNodes = [await doCaptureWindow(xpathTrail)]; | ||
@@ -15,0 +13,0 @@ } else { |
@@ -16,5 +16,5 @@ 'use strict'; | ||
defaultDomProps, | ||
)}, doc=document, {returnCaptureAsString = false} = {}) { | ||
)}, doc=document, {returnCaptureAsString = false, returnStringSectionSize = undefined, sectionGlobalVarName} = {}) { | ||
${bundleFile.code} | ||
return ${filename}(props, doc, {returnCaptureAsString}); | ||
return ${filename}(props, doc, {returnCaptureAsString, returnStringSectionSize, sectionGlobalVarName}); | ||
}`; | ||
@@ -21,0 +21,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
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
39412
17
1117