Bug 1830111 - [devtools] Ignore exception related to nested, invisible iframes. r=devtools-reviewers,nchevobbe

You can add an <iframe> as an immediate children of another <iframe>.
This was causing exception when the walker was processing such nested iframe.
inDeepTreeWalker::SetCurrentNode is throwing because such nested iframe
aren't considered as valid children, even if they are visible via topFrame.children.

Let's ignore this exception as the inspector wouldn't show such iframe anyway.
We only show the inner document for <iframe> and none of the possibly manually added children.

Differential Revision: https://phabricator.services.mozilla.com/D177152
This commit is contained in:
Alexandre Poirot 2023-05-10 14:27:47 +00:00
parent 528ff6e357
commit f317ffb43d
3 changed files with 64 additions and 1 deletions

View File

@ -233,6 +233,7 @@ skip-if = http3 # Bug 1829298
[browser_inspector_search-07.js]
[browser_inspector_search-08.js]
[browser_inspector_search-09.js]
[browser_inspector_search-10.js]
[browser_inspector_search-clear.js]
[browser_inspector_search-filter_context-menu.js]
[browser_inspector_search-label.js]

View File

@ -0,0 +1,52 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Bug 1830111 - Test that searching elements while having hidden <iframe> works
const HTML = `
<!DOCTYPE html>
<html>
<body>
<!-- The nested iframe, will be a children node of the top iframe
but won't be displayed, not considered as valid children by the inspector -->
<iframe><iframe></iframe></iframe>
<div>after iframe</<div>
<script>
document.querySelector("iframe").appendChild(document.createElement("iframe"));
</script>
</body>
</html>
`;
const TEST_URI = "data:text/html;charset=utf-8," + encodeURI(HTML);
add_task(async function() {
const { inspector } = await openInspectorForURL(TEST_URI);
await focusSearchBoxUsingShortcut(inspector.panelWin);
const onSearchProcessingDone = inspector.searchSuggestions.once(
"processing-done"
);
synthesizeKeys("div", inspector.panelWin);
info("Waiting for search query to complete");
await onSearchProcessingDone;
const popup = inspector.searchSuggestions.searchPopup;
const actualSuggestions = popup.getItems().map(item => item.label);
Assert.deepEqual(
actualSuggestions,
["div"],
"autocomplete popup displays the right suggestions"
);
const onSearchResult = inspector.search.once("search-result");
EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin);
info("Waiting for results");
await onSearchResult;
const nodeFront = await getNodeFront("div", inspector);
is(inspector.selection.nodeFront, nodeFront, "The <div> element is selected");
});

View File

@ -2458,7 +2458,17 @@ class WalkerActor extends Actor {
* document fragment
*/
_isInDOMTree(rawNode) {
const walker = this.getDocumentWalker(rawNode);
let walker;
try {
walker = this.getDocumentWalker(rawNode);
} catch (e) {
// The DocumentWalker may throw NS_ERROR_ILLEGAL_VALUE when the node isn't found as a legit children of its parent
// ex: <iframe> manually added as immediate child of another <iframe>
if (e.name == "NS_ERROR_ILLEGAL_VALUE") {
return false;
}
throw e;
}
let current = walker.currentNode;
// Reaching the top of tree