
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@applitools/dom-snapshot
Advanced tools
Script for extracting resources and DOM in CDT format, to serve as the input for rendering a screenshot with the visual grid.
This package is a core dependency used throughout the Applitools ecosystem:
@applitools/eyes-selenium - Selenium WebDriver integration@applitools/eyes-cypress - Cypress testing integration@applitools/eyes-playwright - Playwright testing integration@applitools/core - Shared core functionality across SDKs@applitools/visual-grid-client - Visual Grid rendering serviceTest frameworks inject DOM capture scripts into browser contexts:
// Used by: eyes-selenium, eyes-playwright, etc.
const { getProcessPage } = require('@applitools/dom-snapshot')
const script = await getProcessPage()
const result = await driver.executeScript(`return (${script}).apply(null, arguments);`, args)
Advanced frameworks that pass function objects directly:
// Used by: core package for specific driver capabilities
const processPagePoll = require('@applitools/dom-snapshot/dist/processPagePollCjs')
await driver.executePoll({ main: processPagePoll }, args)
Non-driver based integrations bundle the functions:
// Used by: eyes-cypress (runs in browser context)
import processPage from '@applitools/dom-snapshot/src/browser/processPage'
The package provides the same functionality in multiple formats to support different execution contexts:
src/browser/processPage.js
├── dist/processPage.js (IIFE - Browser injection)
└── dist/processPagePollCjs.js (CommonJS - Node.js execution)
dist/processPage.jsdist/processPagePollCjs.jssrc/browser/processPage.js (raw source)Instead of complex bundling with selective obfuscation, we use direct imports:
// Main package exports - simple script getters
const { getProcessPage, getProcessPagePoll, getPollResult } = require('@applitools/dom-snapshot')
// Direct imports for specific formats
const processPagePoll = require('@applitools/dom-snapshot/dist/processPagePollCjs')
const pollResult = require('@applitools/dom-snapshot/dist/pollResultCjs')
This approach:
Gradual Migration Strategy:
.js and .ts files during transitionnpm install @applitools/dom-snapshot
This package exports functions that can be used when working with puppeteer, CDP or Selenium in Node.js:
getProcessPagegetProcessPagePollgetPollResultThe following methods are deprecated:
getProcessPageAndSerializegetProcessPageAndSerializePollThese async functions return a string with a function that can be sent to the browser for evaluation. It doesn't immediately invoke the function, so the sender should wrap it as an IIFE. For example:
const {getProcessPage} = require('@applitools/dom-snapshot');
const processPage = await getProcessPage();
const returnValue = await page.evaluate(`(${processPage})()`); // puppeteer
By using the non bundled version of the scripts:
src/browser/processPagesrc/browser/processPageAndSerialize (deprecated)These functions can then be bundled together with other client-side code so they are consumed regardless of a browser driver (this is how the Eyes.Cypress SDK uses it).
This package's dist folder contains scripts that can be sent to the browser regradless of driver and language. An agent that wishes to extract information from a webpage can read the contents of dist/processPage and send that to the browser as an async script. There's still the need to wrap it in a way that invokes it.
For example in Java with Selenium WebDriver:
String response = driver.executeAsyncScript("const callback = arguments[arguments.length - 1];(" + processPage + ")().then(JSON.stringify).then(callback, function(err) {callback(err.stack || err.toString())})";
Note for Selenium WebDriver users: The return value must not include objects with the property nodeType. Browser drivers interpret those as HTML nodes, and thus corrupt the result. A possible remedy to this is to JSON.stringify the result before sending it back to the calling process. That's what we're doing in the example above.
processPage scriptOne single argument with the following properties:
processPage({
doc = document,
showLogs,
useSessionCache,
dontFetchResources,
fetchTimeout,
skipResources,
compressResources,
serializeResources,
})
doc - the document for which to take a snapshot. Default: the current document.showLogs - toggle verbose logging in the consoleuseSessionCache - cache resources in the browser's sessionCache. Optimization for cases where processPage is run on the same browser tab more than once.dontFetchResources - dont fetch resources. Only return resourceUrls and not blobs.fetchTimeout - the time it takes to fail on a hanging fetch request for getting a resource. Default: 10000 (10 seconds)skipResources - an array of absolute URL's of resources which shouldn't be fetched by processPage.compressResources - a boolean indicating whether to use the deflate algorithm on blob data in order to return a smaller response. The caller should then inflate the blobs to get the value.serializeResources - a boolean indicating whether to return blob data as base64 strings. This is useful in most cases since the processPage function is generally run from outside the browser, so its response should be serializable.This script receives a document, and returns an object with the following:
url - the URL of the document.cdt - a flat array representing the document's DOM in CDT format.resourceUrls - an array of strings with URL's of resources that appear in the page's DOM or are referenced from a CSS resource but are cross-origin and therefore could not be fetched from the browser.blobs - an array of objects with the following structure: {url, type, value}. These are resources that the browser was able to fetch. The type property is the Content-Type response header. The value property contains an ArrayBuffer with the content of the resource.frames: an array with objects which recursively have the same structure as the processPage return value: {url, cdt, resourceUrls, blobs, frames}.srcAttr - for frames, this is the original src attribute on the frame (in use by Selenium IDE Eyes extension)crossFrames - an array of objects with the following structure: {selector, index}. The selector field has a value of css selector (strings) that point to cross origin frames. The index is an index (number) of frame node in a cdt array, this could be useful to override src attribute once dom snapshot is taken. The caller can then call processPage in the context of those frames in order to build a complete DOM snapshot which also contains cross origin iframes.selector - a css selector (string) for the frame (only for iframes). This is helpful to construct the full frame chain that leads to cross origin iframes on the caller side.The script scans the DOM for resource references, fetches them, and then also scans the body of css resources for more references, and so on recursively.
processPagePollThis function calls processPage and returns immediately. Then pollResult should be called (or any of the ...Poll script variations, for backwards compatibility) to get the polling result.
This function accepts the same arguments as processPage, with one additional parameter:
chunkByteLength - this will cause additional polling after the snapshot is ready, and will transfer the result in chunks, with the chunk size specified. Default: undefined.For example, to pass a maximum chunk size of 256MB:
procesPagePoll({chunkByteLength: 1024 * 1024 * 256})
The polling result is a stringified JSON object, which is of the following shape:
{
status: string,
error: string,
value: object
}
Status could be one of:
value field with the return valueerror field with the resultpollResult to continue polling until "SUCCESS" or "ERROR" are received.pollResult to continue polling until the entire value is received (used with chunkByteLength).pollResultreturns the poll result - an object with the same shape as processPagePoll.
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. While Puppeteer itself does not specialize in capturing and serializing DOM snapshots, it can be used in conjunction with other tools to achieve similar results. Puppeteer is more general-purpose and can be used for a wide range of browser automation tasks.
Selenium WebDriver is a tool for automating web application testing, and it allows you to programmatically control a browser. Like Puppeteer, Selenium WebDriver does not specialize in capturing and serializing DOM snapshots but can be used in combination with other tools to achieve similar functionality. Selenium is more versatile in terms of browser support compared to Puppeteer.
Cypress is a JavaScript end-to-end testing framework that aims to make testing web applications easier. While Cypress focuses on testing, it also provides capabilities to capture the state of the DOM. However, it is not specifically designed for capturing and serializing DOM snapshots like @applitools/dom-snapshot.
FAQs
Unknown package
The npm package @applitools/dom-snapshot receives a total of 270,187 weekly downloads. As such, @applitools/dom-snapshot popularity was classified as popular.
We found that @applitools/dom-snapshot demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 50 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.