The goal of this function is to provide a simple way to extract the DOM of a webpage that can be contained in a single string. We rely on the SingleFile engine to capture the page in a single page.
getCurrentDomWithStyles does not take any arguments and returns a Promise that when resolved contains a string containing the entire dom with all the style elements.
Example of usage:
document.addEventListener('readystatechange', event => {
domWithStyles.getContent().then(function (dom) {
console.log(dom);
});
});
In this example the script is waiting for the page to be loaded, and then displays the computed current dom with styles in the console.
- Move to the root of the project
- Run
npm build
. - A browsified version is created at
<ROOT>/dist/domWithStyles.bundle.js