tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 12f7fad6164ba5466dd6160f5d00600f8fb7dee8
parent b0e33960db736455504422c8f4ec261f22497542
Author: Nicolas Chevobbe <nchevobbe@mozilla.com>
Date:   Fri, 19 Dec 2025 15:37:22 +0000

Bug 2002814 - [devtools] Avoid throwing when seeing a native anonymous node in $$$ console helper. r=devtools-reviewers,ochameau.

The helper was throwing when trying to add an native anonymous node to
the result array as it's seen as a cross origin object.
Wrap the call to Array#push in a try/catch so we avoid throwing
when we're in this case.

Differential Revision: https://phabricator.services.mozilla.com/D277020

Diffstat:
Mdevtools/client/webconsole/test/browser/browser_jsterm_helper_dollar_dollar_dollar.js | 13+++++++++++++
Mdevtools/server/actors/webconsole/commands/manager.js | 10++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/devtools/client/webconsole/test/browser/browser_jsterm_helper_dollar_dollar_dollar.js b/devtools/client/webconsole/test/browser/browser_jsterm_helper_dollar_dollar_dollar.js @@ -23,6 +23,7 @@ const TEST_URI = `data:text/html,<!DOCTYPE html> </template> </div> <div id="3">3</div> + <details><summary>spoil</summary>peekaboo</details> </main>`; add_task(async function () { @@ -103,4 +104,16 @@ add_task(async function () { "Array [ div#2-3.x ]" ); ok(message, "works when passed a scope inside the shadow DOM"); + + message = await executeAndWaitForResultMessage( + hud, + // The <details> element uses a <slot> element to control its layout. It shouldn't + // be returned, but shouldn't make the helper throw (See Bug 2002814) + `$$$("slot, details, summary")`, + "Array [ details, summary ]" + ); + ok( + message, + "works when the selector matches native anonymous node (but don't return them)" + ); }); diff --git a/devtools/server/actors/webconsole/commands/manager.js b/devtools/server/actors/webconsole/commands/manager.js @@ -541,6 +541,16 @@ WebConsoleCommandsManager.register({ // Calling owner.window.Array.from() doesn't work without accessing the // wrappedJSObject, so just loop through the results instead. for (let i = 0, len = nodes.length; i < len; i++) { + // If we have a native anonymous element, it's seen as a cross-origin object + // and can't be added to result. We could waive `result` to avoid this exception, + // but those nodes would show up as `Restricted` (See Bug 2006913), so it's not + // really useful. If we'd have a proper rendering for those, ideally we'd use + // the Inspector Walker filter to see if a node should be skipped or not + // and we could add the node here. + if (nodes[i].isNativeAnonymous) { + continue; + } + result.push(nodes[i]); }