@applitools/dom-capture
Advanced tools
Comparing version 2.0.6 to 2.0.7
const captureDom = require('./src/captureWindow'); | ||
const captureFrame = require('./src/captureFrame'); | ||
const getCaptureDomScript = require('./src/captureDomExport'); | ||
const defaultDomProps = require('./src/defaultDomProps'); | ||
module.exports = { | ||
captureDom, | ||
captureFrame, // backward compatibility. Can probably be removed on December 2018. | ||
getCaptureDomScript, | ||
defaultDomProps, | ||
captureFrame, | ||
}; |
{ | ||
"name": "@applitools/dom-capture", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"main": "index.js", | ||
@@ -9,4 +9,3 @@ "license": "MIT", | ||
"eslint": "eslint '**/*.js'", | ||
"test": "npm run test:mocha && npm run eslint", | ||
"build": "rollup -c rollup.config.js" | ||
"test": "yarn test:mocha && yarn eslint" | ||
}, | ||
@@ -17,24 +16,15 @@ "engines": { | ||
"files": [ | ||
"src", | ||
"dist" | ||
"src" | ||
], | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"chai": "^4.1.2", | ||
"eslint": "^4.19.1", | ||
"eslint-plugin-mocha-no-only": "^0.0.6", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-prettier": "^2.7.0", | ||
"express": "^4.16.4", | ||
"eslint-plugin-prettier": "^2.6.0", | ||
"express": "^4.16.3", | ||
"mocha": "^5.1.1", | ||
"prettier": "^1.14.3", | ||
"puppeteer": "^1.9.0", | ||
"rollup": "^0.66.6", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-node-builtins": "^2.1.2", | ||
"rollup-plugin-node-globals": "^1.4.0", | ||
"rollup-plugin-node-resolve": "^3.4.0" | ||
}, | ||
"dependencies": { | ||
"@applitools/functional-commons": "^1.0.19" | ||
"prettier": "^1.11.1", | ||
"puppeteer": "^1.4.0" | ||
} | ||
} |
/* global window, document */ | ||
'use strict'; | ||
const captureFrameCss = require('./captureCss'); | ||
const defaultDomProps = require('./defaultDomProps'); | ||
async function captureFrame( | ||
{styleProps, rectProps, ignoredTagNames} = defaultDomProps, | ||
doc = document, | ||
) { | ||
function captureFrame({styleProps, attributeProps, rectProps, ignoredTagNames}, doc = document) { | ||
const NODE_TYPES = { | ||
@@ -22,7 +17,7 @@ ELEMENT: 1, | ||
async function iframeToJSON(el) { | ||
const obj = await elementToJSON(el); | ||
function iframeToJSON(el) { | ||
const obj = elementToJSON(el); | ||
try { | ||
if (el.contentDocument) { | ||
obj.childNodes = [await captureNode(el.contentDocument.documentElement)]; | ||
obj.childNodes = [captureNode(el.contentDocument.documentElement)]; | ||
} | ||
@@ -35,3 +30,3 @@ } catch (ex) { | ||
async function elementToJSON(el) { | ||
function elementToJSON(el) { | ||
const tagName = el.tagName.toUpperCase(); | ||
@@ -48,9 +43,15 @@ if (ignoredTagNames.indexOf(tagName) > -1) return null; | ||
const attributes = Array.from(el.attributes) | ||
.map(a => ({key: a.name, value: a.value})) | ||
.reduce((obj, attr) => { | ||
obj[attr.key] = attr.value; | ||
return obj; | ||
}, {}); | ||
const attributes = {}; | ||
if (attributeProps.all) { | ||
for (const p of attributeProps.all) { | ||
if (el.hasAttribute(p)) attributes[p] = el.getAttribute(p); | ||
} | ||
} | ||
if (attributeProps[tagName]) { | ||
for (const p of attributeProps[tagName]) { | ||
if (el.hasAttribute(p)) attributes[p] = el.getAttribute(p); | ||
} | ||
} | ||
return { | ||
@@ -61,5 +62,3 @@ tagName, | ||
attributes: notEmptyObj(attributes), | ||
childNodes: (await Promise.all(Array.prototype.map.call(el.childNodes, captureNode))).filter( | ||
filter, | ||
), | ||
childNodes: Array.prototype.map.call(el.childNodes, captureNode).filter(filter), | ||
}; | ||
@@ -75,3 +74,3 @@ } | ||
async function captureNode(node) { | ||
function captureNode(node) { | ||
switch (node.nodeType) { | ||
@@ -82,10 +81,5 @@ case NODE_TYPES.TEXT: | ||
if (node.tagName.toUpperCase() === 'IFRAME') { | ||
return await iframeToJSON(node); | ||
return iframeToJSON(node); | ||
} else { | ||
const retVal = await elementToJSON(node); | ||
if (node.tagName.toUpperCase() === 'HTML') { | ||
const css = await captureFrameCss(window.location, node); | ||
retVal.css = css; | ||
} | ||
return retVal; | ||
return elementToJSON(node); | ||
} | ||
@@ -97,5 +91,5 @@ default: | ||
return await captureNode(doc.documentElement); | ||
return captureNode(doc.documentElement); | ||
} | ||
module.exports = {captureFrame}; | ||
module.exports = captureFrame; |
@@ -0,4 +1,4 @@ | ||
const captureFrame = require('./captureFrame'); | ||
const defaultDomProps = require('./defaultDomProps'); | ||
const genXpath = require('./genXpath'); | ||
const getCaptureDomScript = require('./captureDomExport'); | ||
@@ -44,3 +44,3 @@ async function captureWindow(runScript, domProps) { | ||
const args = JSON.stringify(mergedDomProps); | ||
const scriptStr = `return (${await getCaptureDomScript()})(${args})`; //`return (${script})(${args})`; | ||
const scriptStr = `return (${captureFrame})(${args})`; | ||
@@ -47,0 +47,0 @@ return await doCaptureWindow(); |
@@ -23,2 +23,9 @@ // TODO conditionally add/remove properties based on value (need to account for cross browser values) | ||
const attributeProps = { | ||
all: ['id', 'class'], | ||
IMG: ['src'], | ||
IFRAME: ['src'], | ||
A: ['href'], | ||
}; | ||
const ignoredTagNames = ['HEAD']; | ||
@@ -29,3 +36,4 @@ | ||
rectProps, | ||
attributeProps, | ||
ignoredTagNames, | ||
}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
9
1
1
5668
7
164
- Removed@applitools/functional-commons@1.6.0(transitive)