Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to deep clone a JSDOM object? #3693

Open
dartanian300 opened this issue Mar 13, 2024 · 0 comments
Open

Is there a way to deep clone a JSDOM object? #3693

dartanian300 opened this issue Mar 13, 2024 · 0 comments

Comments

@dartanian300
Copy link

Is there a way to completely deep clone a JSDOM object? So you could make changes (add/delete nodes, change id's, etc) without affecting the original dom.

Example:

const jsdom = require("jsdom");
const page = new JSDOM(`
<html>
    <head></head>
    <body>
        <div id='original_id'></div>
    </body>
</html>
`);

const page2 = page.clone();  // Does something like this exist?

// Make modifications to page2 without them affecting page 
page2.window.document.querySelector('div').id = 'new_id';

console.log("page1 id: ", page1.window.document.querySelector('div').id);
console.log("page2 id: ", page2.window.document.querySelector('div').id);

Expected output:

page1 id: original_id
page2 id: new_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant