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
96
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 3.1.4 to 3.1.5

src/captureFrameCss.js

152

dist/captureDom.js

@@ -1,2 +0,4 @@

var _captureDom = (function (exports) {
function(props={"styleProps":["background-color","background-image","background-size","color","border-width","border-color","border-style","padding","margin"],"rectProps":["width","height","top","left","bottom","right"],"ignoredTagNames":["HEAD"]}, doc=document) {
var captureDom = (function () {
'use strict';

@@ -106,8 +108,7 @@

async function captureFrameCss(url, frame) {
const css = (await captureNodeCss(url, frame)) || '';
return css;
async function captureFrameCss(url, doc) {
return await captureNodeCss(url, doc.documentElement);
}
var captureCss = captureFrameCss;
var captureFrameCss_1 = captureFrameCss;

@@ -200,73 +201,77 @@ // TODO conditionally add/remove properties based on value (need to account for cross browser values)

async function iframeToJSON(el) {
const obj = await elementToJSON(el);
try {
if (el.contentDocument) {
obj.childNodes = [await captureNode(el.contentDocument.documentElement)];
function captureTextNode(node) {
return {
tagName: '#text',
text: node.textContent,
};
}
async function doCaptureFrame(frameDoc) {
const bgImages = new Set();
const ret = await captureNode(frameDoc.documentElement);
ret.css = await captureFrameCss_1(window.location, frameDoc);
ret.images = await getImageSizes_1({bgImages});
return ret;
async function captureNode(node) {
switch (node.nodeType) {
case NODE_TYPES.TEXT:
return captureTextNode(node);
case NODE_TYPES.ELEMENT:
const tagName = node.tagName.toUpperCase();
if (tagName === 'IFRAME') {
return await iframeToJSON(node);
} else {
return await await elementToJSON(node);
}
default:
return null;
}
} catch (ex) {
} finally {
return obj;
}
}
async function elementToJSON(el) {
const tagName = el.tagName.toUpperCase();
if (ignoredTagNames.indexOf(tagName) > -1) return null;
const computedStyle = window.getComputedStyle(el);
const boundingClientRect = el.getBoundingClientRect();
async function elementToJSON(el) {
const tagName = el.tagName.toUpperCase();
if (ignoredTagNames.indexOf(tagName) > -1) return null;
const computedStyle = window.getComputedStyle(el);
const boundingClientRect = el.getBoundingClientRect();
const style = {};
for (const p of styleProps) style[p] = computedStyle.getPropertyValue(p);
const style = {};
for (const p of styleProps) style[p] = computedStyle.getPropertyValue(p);
const rect = {};
for (const p of rectProps) rect[p] = boundingClientRect[p];
const rect = {};
for (const p of rectProps) rect[p] = boundingClientRect[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;
}, {});
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 bgImage = getBackgroundImageUrl_1(computedStyle.getPropertyValue('background-image'));
if (bgImage) {
bgImages.add(bgImage);
const bgImage = getBackgroundImageUrl_1(computedStyle.getPropertyValue('background-image'));
if (bgImage) {
bgImages.add(bgImage);
}
return {
tagName,
style: notEmptyObj(style),
rect: notEmptyObj(rect),
attributes: notEmptyObj(attributes),
childNodes: (await Promise.all(
Array.prototype.map.call(el.childNodes, captureNode),
)).filter(filter),
};
}
return {
tagName,
style: notEmptyObj(style),
rect: notEmptyObj(rect),
attributes: notEmptyObj(attributes),
childNodes: (await Promise.all(Array.prototype.map.call(el.childNodes, captureNode))).filter(
filter,
),
};
}
function captureTextNode(node) {
return {
tagName: '#text',
text: node.textContent,
};
}
async function captureNode(node) {
switch (node.nodeType) {
case NODE_TYPES.TEXT:
return captureTextNode(node);
case NODE_TYPES.ELEMENT:
if (node.tagName.toUpperCase() === 'IFRAME') {
return await iframeToJSON(node);
} else {
const retVal = await elementToJSON(node);
if (node.tagName.toUpperCase() === 'HTML') {
const css = await captureCss(window.location, node);
retVal.css = css;
}
return retVal;
async function iframeToJSON(el) {
const obj = await elementToJSON(el);
try {
if (el.contentDocument) {
obj.childNodes = [await doCaptureFrame(el.contentDocument)];
}
default:
return null;
} catch (ex) {
} finally {
return obj;
}
}

@@ -276,5 +281,3 @@ }

const start = Date.now();
const bgImages = new Set();
const ret = await captureNode(doc.documentElement);
ret.images = await getImageSizes_1({bgImages});
const ret = await doCaptureFrame(doc);
console.log('[captureFrame]', Date.now() - start);

@@ -284,10 +287,9 @@ return ret;

var captureFrame_1 = {captureFrame};
var captureFrame_2 = captureFrame_1.captureFrame;
var captureFrame_1 = captureFrame;
exports.default = captureFrame_1;
exports.captureFrame = captureFrame_2;
return captureFrame_1;
return exports;
}());
}({}));
return captureDom(props, doc);
}

@@ -1,7 +0,7 @@

const captureDom = require('./src/captureWindow');
const captureWindow = require('./src/captureWindow');
const captureFrame = require('./src/captureFrame');
const getCaptureDomScript = require('./src/captureDomExport');
const getCaptureDomScript = require('./src/getCaptureDomScript');
const defaultDomProps = require('./src/defaultDomProps');
module.exports = {
captureDom,
captureWindow,
captureFrame, // backward compatibility. Can probably be removed on December 2018.

@@ -8,0 +8,0 @@ getCaptureDomScript,

{
"name": "@applitools/dom-capture",
"version": "3.1.4",
"version": "3.1.5",
"main": "index.js",

@@ -5,0 +5,0 @@ "license": "MIT",

/* global window, document */
'use strict';
const captureFrameCss = require('./captureCss');
const captureFrameCss = require('./captureFrameCss');
const defaultDomProps = require('./defaultDomProps');

@@ -25,73 +25,77 @@ const getBackgroundImageUrl = require('./getBackgroundImageUrl');

async function iframeToJSON(el) {
const obj = await elementToJSON(el);
try {
if (el.contentDocument) {
obj.childNodes = [await captureNode(el.contentDocument.documentElement)];
function captureTextNode(node) {
return {
tagName: '#text',
text: node.textContent,
};
}
async function doCaptureFrame(frameDoc) {
const bgImages = new Set();
const ret = await captureNode(frameDoc.documentElement);
ret.css = await captureFrameCss(window.location, frameDoc);
ret.images = await getImageSizes({bgImages});
return ret;
async function captureNode(node) {
switch (node.nodeType) {
case NODE_TYPES.TEXT:
return captureTextNode(node);
case NODE_TYPES.ELEMENT:
const tagName = node.tagName.toUpperCase();
if (tagName === 'IFRAME') {
return await iframeToJSON(node);
} else {
return await await elementToJSON(node);
}
default:
return null;
}
} catch (ex) {
} finally {
return obj;
}
}
async function elementToJSON(el) {
const tagName = el.tagName.toUpperCase();
if (ignoredTagNames.indexOf(tagName) > -1) return null;
const computedStyle = window.getComputedStyle(el);
const boundingClientRect = el.getBoundingClientRect();
async function elementToJSON(el) {
const tagName = el.tagName.toUpperCase();
if (ignoredTagNames.indexOf(tagName) > -1) return null;
const computedStyle = window.getComputedStyle(el);
const boundingClientRect = el.getBoundingClientRect();
const style = {};
for (const p of styleProps) style[p] = computedStyle.getPropertyValue(p);
const style = {};
for (const p of styleProps) style[p] = computedStyle.getPropertyValue(p);
const rect = {};
for (const p of rectProps) rect[p] = boundingClientRect[p];
const rect = {};
for (const p of rectProps) rect[p] = boundingClientRect[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;
}, {});
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 bgImage = getBackgroundImageUrl(computedStyle.getPropertyValue('background-image'));
if (bgImage) {
bgImages.add(bgImage);
const bgImage = getBackgroundImageUrl(computedStyle.getPropertyValue('background-image'));
if (bgImage) {
bgImages.add(bgImage);
}
return {
tagName,
style: notEmptyObj(style),
rect: notEmptyObj(rect),
attributes: notEmptyObj(attributes),
childNodes: (await Promise.all(
Array.prototype.map.call(el.childNodes, captureNode),
)).filter(filter),
};
}
return {
tagName,
style: notEmptyObj(style),
rect: notEmptyObj(rect),
attributes: notEmptyObj(attributes),
childNodes: (await Promise.all(Array.prototype.map.call(el.childNodes, captureNode))).filter(
filter,
),
};
}
function captureTextNode(node) {
return {
tagName: '#text',
text: node.textContent,
};
}
async function captureNode(node) {
switch (node.nodeType) {
case NODE_TYPES.TEXT:
return captureTextNode(node);
case NODE_TYPES.ELEMENT:
if (node.tagName.toUpperCase() === 'IFRAME') {
return await 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;
async function iframeToJSON(el) {
const obj = await elementToJSON(el);
try {
if (el.contentDocument) {
obj.childNodes = [await doCaptureFrame(el.contentDocument)];
}
default:
return null;
} catch (ex) {
} finally {
return obj;
}
}

@@ -101,5 +105,3 @@ }

const start = Date.now();
const bgImages = new Set();
const ret = await captureNode(doc.documentElement);
ret.images = await getImageSizes({bgImages});
const ret = await doCaptureFrame(doc);
console.log('[captureFrame]', Date.now() - start);

@@ -109,2 +111,2 @@ return ret;

module.exports = {captureFrame};
module.exports = captureFrame;
const defaultDomProps = require('./defaultDomProps');
const genXpath = require('./genXpath');
const getCaptureDomScript = require('./captureDomExport');
const getCaptureDomScript = require('./getCaptureDomScript');

@@ -5,0 +5,0 @@ async function captureWindow(runScript, domProps) {

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