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.6 to 2.0.7

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, // backward compatibility. Can probably be removed on December 2018.
getCaptureDomScript,
defaultDomProps,
captureFrame,
};

26

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