Closed Bug 1839663 Opened 2 years ago Closed 2 years ago

Console helpers $ & $$ should support a second argument as root for the query

Categories

(DevTools :: Console, defect, P3)

defect

Tracking

(firefox117 verified, firefox118 verified)

VERIFIED FIXED
117 Branch
Tracking Status
firefox117 --- verified
firefox118 --- verified

People

(Reporter: 6aw5gz2lx, Assigned: felix.lefebvre, Mentored)

Details

(Whiteboard: [lang=js])

Attachments

(2 files)

Attached file Example page

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 with function () { [native code] }. For convenience added index.html file which was used for reproducing, it includes 2 div tags with class a and b respectively, each of them contains 3 p tags and doesn't inject any JavaScript.

Steps to reproduce:

  1. Open provided index.html file and open Web Console.
  2. 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.

is that something you could help with ?
thanks

Component: Firefox Source Docs: Content → Console
Flags: needinfo?(nchevobbe)
Product: Developer Infrastructure → DevTools

I'm mostly curious if it's a typo in docs or there's something with $ & $$ implementation in Firefox.

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

Flags: needinfo?(nchevobbe)

Note that chrome supports this second argument.

Since it's implemented in Chrome and used to work in Firebug, let's try to add this feature to align with the documentation.

Mentor: nchevobbe
Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Summary: Dollar ($ & $$) helper functions don't work as documented → Console helpers $ & $$ should support a second argument as root for the query
Whiteboard: [lang=js]
Assignee: nobody → felix.lefebvre
Status: NEW → ASSIGNED

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.

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.

Felix, did you see my comments on Phabricator? Just checking that you're not blocked on anything :)

Flags: needinfo?(felix.lefebvre)

I did thanks! I'll give it a revision in the upcoming days.

Flags: needinfo?(felix.lefebvre)
Pushed by nchevobbe@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f7b5f4a504ac Add second argument support to helper functions r=devtools-reviewers,nchevobbe
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 117 Branch

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.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: