Merge remote-tracking branch 'refs/remotes/origin/fix/happy-dom-process-variable' into fix/happy-dom-process-variable

This commit is contained in:
bdbch 2025-05-23 22:34:24 +02:00
commit c0bad9fce0
3 changed files with 16 additions and 1 deletions

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')

View File

@ -2,6 +2,13 @@ import type { Window as HappyDOMWindow } from 'happy-dom-without-node'
import { preserveAndRestoreNodeInternals } from './preserveAndRestoreNodeInternals.js'
/**
* Creates a new `Window` instance using `happy-dom` and ensures that the original
* `process` object is restored after the operation. This function wraps the
* creation of the `Window` object to provide a safe environment for DOM manipulation.
*
* @returns {HappyDOMWindow} A new `Window` instance from `happy-dom`.
*/
export function createSafeWindow() {
return preserveAndRestoreNodeInternals(() => {
const { Window } = require('happy-dom-without-node')

View File

@ -7,7 +7,7 @@ export function preserveAndRestoreNodeInternals<T>(operation: () => T): T {
// Store the original process object
// see https://github.com/ueberdosis/tiptap/issues/6368
// eslint-disable-next-line
const originalProcess = globalThis?.process
const originalProcess = globalThis.process
try {
return operation()