@applitools/dom-capture
Advanced tools
Comparing version 2.0.7 to 3.0.0
const captureDom = require('./src/captureWindow'); | ||
const captureFrame = require('./src/captureFrame'); | ||
const getCaptureDomScript = require('./src/captureDomExport'); | ||
const defaultDomProps = require('./src/defaultDomProps'); | ||
module.exports = { | ||
captureDom, | ||
captureFrame, | ||
captureFrame, // backward compatibility. Can probably be removed on December 2018. | ||
getCaptureDomScript, | ||
defaultDomProps, | ||
}; |
{ | ||
"name": "@applitools/dom-capture", | ||
"version": "2.0.7", | ||
"version": "3.0.0", | ||
"main": "index.js", | ||
@@ -9,3 +9,4 @@ "license": "MIT", | ||
"eslint": "eslint '**/*.js'", | ||
"test": "yarn test:mocha && yarn eslint" | ||
"test": "npm run test:mocha && npm run eslint", | ||
"build": "rollup -c rollup.config.js" | ||
}, | ||
@@ -16,15 +17,24 @@ "engines": { | ||
"files": [ | ||
"src" | ||
"src", | ||
"dist" | ||
], | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"chai": "^4.2.0", | ||
"eslint": "^4.19.1", | ||
"eslint-plugin-mocha-no-only": "^0.0.6", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-prettier": "^2.6.0", | ||
"express": "^4.16.3", | ||
"eslint-plugin-prettier": "^2.7.0", | ||
"express": "^4.16.4", | ||
"mocha": "^5.1.1", | ||
"prettier": "^1.11.1", | ||
"puppeteer": "^1.4.0" | ||
"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" | ||
} | ||
} |
/* global window, document */ | ||
function captureFrame({styleProps, attributeProps, rectProps, ignoredTagNames}, doc = document) { | ||
'use strict'; | ||
const captureFrameCss = require('./captureCss'); | ||
const defaultDomProps = require('./defaultDomProps'); | ||
async function captureFrame( | ||
{styleProps, rectProps, ignoredTagNames} = defaultDomProps, | ||
doc = document, | ||
) { | ||
const NODE_TYPES = { | ||
@@ -17,7 +22,7 @@ ELEMENT: 1, | ||
function iframeToJSON(el) { | ||
const obj = elementToJSON(el); | ||
async function iframeToJSON(el) { | ||
const obj = await elementToJSON(el); | ||
try { | ||
if (el.contentDocument) { | ||
obj.childNodes = [captureNode(el.contentDocument.documentElement)]; | ||
obj.childNodes = [await captureNode(el.contentDocument.documentElement)]; | ||
} | ||
@@ -30,3 +35,3 @@ } catch (ex) { | ||
function elementToJSON(el) { | ||
async function elementToJSON(el) { | ||
const tagName = el.tagName.toUpperCase(); | ||
@@ -43,15 +48,9 @@ if (ignoredTagNames.indexOf(tagName) > -1) return null; | ||
const attributes = {}; | ||
if (attributeProps.all) { | ||
for (const p of attributeProps.all) { | ||
if (el.hasAttribute(p)) attributes[p] = el.getAttribute(p); | ||
} | ||
} | ||
const attributes = Array.from(el.attributes) | ||
.map(a => ({key: a.name, value: a.value})) | ||
.reduce((obj, attr) => { | ||
obj[attr.key] = attr.value; | ||
return obj; | ||
}, {}); | ||
if (attributeProps[tagName]) { | ||
for (const p of attributeProps[tagName]) { | ||
if (el.hasAttribute(p)) attributes[p] = el.getAttribute(p); | ||
} | ||
} | ||
return { | ||
@@ -62,3 +61,5 @@ tagName, | ||
attributes: notEmptyObj(attributes), | ||
childNodes: Array.prototype.map.call(el.childNodes, captureNode).filter(filter), | ||
childNodes: (await Promise.all(Array.prototype.map.call(el.childNodes, captureNode))).filter( | ||
filter, | ||
), | ||
}; | ||
@@ -74,3 +75,3 @@ } | ||
function captureNode(node) { | ||
async function captureNode(node) { | ||
switch (node.nodeType) { | ||
@@ -81,5 +82,10 @@ case NODE_TYPES.TEXT: | ||
if (node.tagName.toUpperCase() === 'IFRAME') { | ||
return iframeToJSON(node); | ||
return await iframeToJSON(node); | ||
} else { | ||
return elementToJSON(node); | ||
const retVal = await elementToJSON(node); | ||
if (node.tagName.toUpperCase() === 'HTML') { | ||
const css = await captureFrameCss(window.location, node); | ||
retVal.css = css; | ||
} | ||
return retVal; | ||
} | ||
@@ -91,5 +97,5 @@ default: | ||
return captureNode(doc.documentElement); | ||
return await captureNode(doc.documentElement); | ||
} | ||
module.exports = captureFrame; | ||
module.exports = {captureFrame}; |
@@ -1,4 +0,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 (${captureFrame})(${args})`; | ||
const scriptStr = `return (${await getCaptureDomScript()})(${args})`; //`return (${script})(${args})`; | ||
@@ -47,0 +47,0 @@ return await doCaptureWindow(); |
@@ -23,9 +23,2 @@ // 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']; | ||
@@ -36,4 +29,3 @@ | ||
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
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
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
16594
11
491
1
14
2
4
+ Added@applitools/functional-commons@1.6.0(transitive)