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);
},
JSDOMParser'sElementreflects several HTML attributes as properties such asclassName,id,href,src,srcset, but notlang. Code that readsdoc.documentElement.langgetsundefinedon 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 aslangon the parse result. The problem hits consumers that take a document back fromJSDOMParserand read the DOM property.Firefox for Android's Reader View hit exactly this. It caches a parsed document, reloads it through
JSDOMParser, and readdoc.documentElement.lang, which gave no language on the cached path. We worked around it withgetAttribute, 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: