Update packages/html/src/createSafeParser.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
bdbch 2025-05-23 21:12:45 +02:00 committed by GitHub
parent 08b158d10e
commit 70ff7a1721
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,14 @@ import type { DOMParser as HappyDOMParser, Window as HappyDOMWindow } from 'happ
import { preserveAndRestoreNodeInternals } from './preserveAndRestoreNodeInternals.js'
/**
* Creates a safe DOMParser instance by wrapping `happy-dom`'s `DOMParser`.
* This function ensures that the original `process` is preserved by using
* `preserveAndRestoreNodeInternals`.
*
* @param {HappyDOMWindow} window - The `happy-dom` window object to use for the parser.
* @returns {HappyDOMParser} A new instance of `happy-dom`'s `DOMParser`.
*/
export function createSafeParser(window: HappyDOMWindow) {
return preserveAndRestoreNodeInternals(() => {
const { DOMParser } = require('happy-dom-without-node')