Skip to content

Instantly share code, notes, and snippets.

@cpojer
Last active January 12, 2026 04:55
Show Gist options
  • Select an option

  • Save cpojer/e66f9a082021a82230f2595a6027f161 to your computer and use it in GitHub Desktop.

Select an option

Save cpojer/e66f9a082021a82230f2595a6027f161 to your computer and use it in GitHub Desktop.
diff --git a/lib/jsdom/browser/Window.js b/lib/jsdom/browser/Window.js
index 52d011cae61c3688ec64baa5cec411d55edbda9d..298d7ec8d2cc1ea5e974262b978e6041389900f7 100644
--- a/lib/jsdom/browser/Window.js
+++ b/lib/jsdom/browser/Window.js
@@ -507,8 +507,8 @@ function installOwnProperties(window, options) {
// [LegacyUnforgeable]:
window: { configurable: false },
document: { configurable: false },
- location: { configurable: false },
- top: { configurable: false }
+ location: { configurable: true },
+ top: { configurable: false },
});
@cpojer
Copy link
Author

cpojer commented Jun 9, 2025

Put this into a patches folder and add this configuration to your package.json:

"pnpm": {
    "patchedDependencies": {
      "jsdom": "patches/jsdom.patch"
    }
  }

@JoshMcCullough
Copy link

Using patch-package to apply this. 👍

@maapteh
Copy link

maapteh commented Aug 26, 2025

for jsdom 26.1.0 it shifted one line (i guess it will happen in between versions a lot)

diff --git a/lib/jsdom/browser/Window.js b/lib/jsdom/browser/Window.js
index 52d011cae61c3688ec64baa5cec411d55edbda9d..298d7ec8d2cc1ea5e974262b978e6041389900f7 100644
--- a/lib/jsdom/browser/Window.js
+++ b/lib/jsdom/browser/Window.js
@@ -507,8 +507,8 @@ function installOwnProperties(window, options) {
     // [LegacyUnforgeable]:
     window: { configurable: false },
     document: { configurable: false },
-    location: { configurable: false },
-    top: { configurable: false }
+    location: { configurable: true },
+    top: { configurable: false },
   });
 
 

@cpojer
Copy link
Author

cpojer commented Aug 27, 2025

@maapteh Thanks, I updated the gist.

@maapteh
Copy link

maapteh commented Aug 27, 2025

Maybe its handy to keep every version isolated, not many people need to stay latest. Thank you for your work! Hopefully something better will arrive with Jest :)

@bbkfhq
Copy link

bbkfhq commented Jan 12, 2026

FYI this no longer seems to work on jsdom 27.4.0 (of course line numbers have changed, but I mean the patch in general doesn't work anymore). Despite setting configurable to true, I get Error: Not implemented: navigation (except hash changes).

Edit: Never mind. My issue was that I had a direct dependency against jsdom. I removed it from my own package and just use jest-environment-jsdom which internally depends on jsdom.

Then you need to create this patch file patches/jest-environment-jsdom++jsdom+26.1.0.patch

(This will patch the jsdom that is inside jest-environment-jsdom)

diff --git a/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js b/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js
index 52d011c..5b29f5a 100644
--- a/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js
+++ b/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js
@@ -507,7 +507,7 @@ function installOwnProperties(window, options) {
     // [LegacyUnforgeable]:
     window: { configurable: false },
     document: { configurable: false },
-    location: { configurable: false },
+    location: { configurable: true },
     top: { configurable: false }
   });

And run npx patch-package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment