Accessing Element.labels may cause a (misleading) getElementById warning message
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
People
(Reporter: nchevobbe, Unassigned)
Details
Steps to reproduce
- Go to
data:text/html,<meta charset=utf8><label id="label1" for="">Label 1</label><input id=""><script>console.log(document.querySelector("input").labels)</script>
- Open the console
Actual results
The following warning message is displayed in the console:
Empty string passed to getElementById()
(defined in https://searchfox.org/mozilla-release/rev/713683b4a6b03aba9e6bd80d65a8e13c462f071a/dom/locales/en-US/chrome/dom/dom.properties#25, emitted from https://searchfox.org/mozilla-release/rev/713683b4a6b03aba9e6bd80d65a8e13c462f071a/dom/base/nsContentUtils.cpp#3998-4001)
This can be quite confusing for the user because clicking on the message location will make them jump to the line where the labels
access is done (where there are no mentions of getElementById
to be found.
That's something a couple folks (me included) experienced while investigating Bug 1750214.
We could have a better warning message saying that one element as an empty string id.
Reporter | ||
Comment 1•3 years ago
|
||
cc'ing smaug as I think he implemented labels
and might have an idea of what to do here.
Comment 2•3 years ago
|
||
https://searchfox.org/mozilla-central/rev/7056a708787621758bef9793a93aa7ca8375eeef/dom/base/DocumentOrShadowRoot.cpp#237,239
I guess the caller could explicitly check whether the string is empty and that way avoid the warning.
Though, do we want another warning hinting that for="" is empty?
Updated•3 years ago
|
Description
•