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

@applitools/dom-capture

Package Overview
Dependencies
Maintainers
12
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@applitools/dom-capture - npm Package Compare versions

Comparing version 2.0.7 to 3.0.0

dist/captureDom.js

6

index.js
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,
};

26

package.json
{
"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,
};
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