8000 [bug] Cannot add property _currentElement, object is not extensible · Issue #3175 · jsdom/jsdom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[bug] Cannot add property _currentElement, object is not extensible #3175

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

Closed
boopathi opened this issue Apr 12, 2021 · 4 comments
Closed

[bug] Cannot add property _currentElement, object is not extensible #3175

boopathi opened this issue Apr 12, 2021 · 4 comments

Comments

@boopathi
Copy link

Basic info:

  • Node.js version: 12, 14
  • jsdom version: 16.5.3

Minimal reproduction case

I pushed a minimal reproduction to this repo - https://github.com/boopathi/jsdom-bug-1

The CI build in that repo would provide the error details - https://github.com/boopathi/jsdom-bug-1/runs/2328255180?check_suite_focus=true

const { PurgeCSS } = require("purgecss");
const fromHtml = require("purgecss-from-html");

// no need to use this. using purgecss-from-html which uses parse5 would fail
require("jsdom");

// use purgecss and fromHtml
// purgecss would fail because JSDOM extends an internal parse5 method.

When JSDOM and parse5 (purgecss-from-html uses parse5) are used imported in the same context, the following error is thrown -

TypeError: Cannot add property _currentElement, object is not extensible

The stack trace of this error points to

// Horrible monkey-patch to implement https://github.com/inikulin/parse5/issues/237 and
// https://github.com/inikulin/parse5/issues/285.
const OpenElementStack = require("parse5/lib/parser/open-element-stack");
const openElementStackOriginalPush = OpenElementStack.prototype.push;
OpenElementStack.prototype.push = function (...args) {
openElementStackOriginalPush.apply(this, args);
this.treeAdapter._currentElement = this.current;
const after = this.items[this.stackTop];
if (after._pushedOnStackOfOpenElements) {
after._pushedOnStackOfOpenElements();
}
};

How does similar code behave in browsers?

This section is not relevant for this issue.

(Link to a jsbin or similar strongly suggested.)

@domenic
Copy link
Member
domenic commented Apr 12, 2021

Yeah, jsdom is not compatible with other things which monkeypatch parse5, I guess. It's a shame we have to do so, but until inikulin/parse5#237 is fixed I don't see a way around that.

@TimothyGu
Copy link
Member

Could we perhaps be at least a bit more careful with the monkey patching? I.e., do something like

 OpenElementStack.prototype.push = function (...args) {
   openElementStackOriginalPush.apply(this, args);
 
+  if (this.treeAdapter instanceof JSDOMParse5Adapter) {
     this.treeAdapter._currentElement = this.current;
+  }
 
   const after = this.items[this.stackTop];
   if (after._pushedOnStackOfOpenElements) {
     after._pushedOnStackOfOpenElements();
   }
 };

That'll fix this case at least.

8000

@bilal68
Copy link
bilal68 commented Aug 16, 2021

how can I slect all the img tags with the property "itemId" present in them i.e:

So when I should do this "document.querySelectorAll("img")" it must gave me 3 tags....any help woud be appericiated.

@domenic
Copy link
Member
domenic commented Apr 20, 2025

This is almost certainly fixed by #3354. I won't add a regression test since pulling in third-party dependencies just for testing is a bit annoying.

@domenic domenic closed this as completed Apr 20, 2025
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

4 participants
0