Console helpers $ & $$ should support a second argument as root for the query
Categories
(DevTools :: Console, defect, P3)
Tracking
(firefox117 verified, firefox118 verified)
People
(Reporter: 6aw5gz2lx, Assigned: felix.lefebvre, Mentored)
Details
(Whiteboard: [lang=js])
Attachments
(2 files)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0
Steps to reproduce:
Web Console Helpers page states that specifying element
argument in $(selector, element)
and $$(selector, element)
should limit results to descended ones, but that doesn't seem true, at least for Firefox 114.
Prerequisites:
- Make sure jQuery or MooTools did not take place of those functions. That can be checked by running
$+''
and$$+''
commands that should respond withfunction () { [native code] }
. For convenience added index.html file which was used for reproducing, it includes 2 div tags with classa
andb
respectively, each of them contains 3p
tags and doesn't inject any JavaScript.
Steps to reproduce:
- Open provided index.html file and open Web Console.
- Run next commands:
$$('p').length
$$('p', document.querySelector('.b')).length
$('.a', document.querySelector('.b'))
Actual results:
Responses from previous three commands are:
- 6
- 6
- <div class="a">
First response is correct as there are 6 p
tags in total.
Second response should 3, as there's only 3 p tags inside of .a
tag.
Third response should be null, as there's no .a
inside of .b
tag.
Basing on these results we can tell that element
argument is always ignored.
Expected results:
These commands should've return:
- 6
- 3
- null
Also tried to check this on Google Chrome 114 and it worked there as intended.
Web Console Helpers page mentioned above.
Comment 2•2 years ago
|
||
is that something you could help with ?
thanks
I'm mostly curious if it's a typo in docs or there's something with $ & $$ implementation in Firefox.
Comment 4•2 years ago
|
||
The helpers only take a single argument (https://searchfox.org/mozilla-central/rev/d31e56f7b3c2c18b8071a7b2a2fb6b4e01e3d3e8/devtools/server/actors/webconsole/commands/manager.js#254,271), and it seemed to have been this way since the helper was introduced (as far as I can tell)
Maybe the doc was somehow carried over from Firebug ?
We should fix the documentation
Comment 5•2 years ago
|
||
Note that chrome supports this second argument.
Comment 6•2 years ago
|
||
Since it's implemented in Chrome and used to work in Firebug, let's try to add this feature to align with the documentation.
Assignee | ||
Comment 7•2 years ago
|
||
Updated•2 years ago
|
Assignee | ||
Comment 8•2 years ago
|
||
Hi,
I've followed along the contribution guide to submit my first code revision to Firefox :)
I'm open to any comments that could help me improve my workflow and craft, cheers!
I think it would be good to take a look on Firebug implementation of those, specifically validating second argument, like in case with Chrome implementation it just ignores second argument when it's not element.
Reporter | ||
Comment 10•2 years ago
|
||
Also return type at $$ https://searchfox.org/mozilla-central/rev/d31e56f7b3c2c18b8071a7b2a2fb6b4e01e3d3e8/devtools/server/actors/webconsole/commands/manager.js#268
@return NodeList
likely needs to be updated too as it actually returns array of nodes, same as Chrome does.
Comment 11•2 years ago
|
||
Felix, did you see my comments on Phabricator? Just checking that you're not blocked on anything :)
Assignee | ||
Comment 12•2 years ago
|
||
I did thanks! I'll give it a revision in the upcoming days.
Comment 13•2 years ago
|
||
Comment 14•2 years ago
|
||
bugherder |
Updated•2 years ago
|
Reproducible on a 2023-07-15 Nightly build on macOS 12.
Verified as fixed on Firefox 117.0b4(build ID: 20230807001816) and Nightly 118.0a1(build ID: 20230807215239) on macOS 12, Ubuntu 22, Windows 10.
Description
•