JSDOMParser: Element is missing a lang accessor
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.5k
- Forks
- 732
- PR merge metrics
- No merged PRs in 30d
Description
JSDOMParser's Element reflects several HTML attributes as properties such as className, id, href, src, srcset, but not lang. Code that reads doc.documentElement.lang gets undefined on a JSDOMParser document, and the language tag on a real DOM document.
Readability itself is not broken by this. It reads the value with getAttribute("lang") (Readability.js:1071) and exposes it as lang on the parse result. The problem hits consumers that take a document back from JSDOMParser and read the DOM property.
Firefox for Android's Reader View hit exactly this. It caches a parsed document, reloads it through JSDOMParser, and read doc.documentElement.lang, which gave no language on the cached path. We worked around it with getAttribute, but the accessor is worth having so the parser matches the DOM.
See also: Bugzilla: https://bugzilla.mozilla.org/show_bug.cgi?id=2062976
Suggested fix
Add the accessor next to the others:
get lang() {
return this.getAttribute("lang") || "";
},
set lang(str) {
this.setAttribute("lang", str);
},
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Find JSDOMParser's Element attribute accessors and inspect the surrounding implementations. Add the lang property behavior shown in the issue, then verify that documentElement.lang reflects the lang attribute and that assigning it updates the attribute.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 76/100