Bug 1810009 - [devtools] Avoid firing DOCUMENT_EVENT will-navigate for non-top-level targets. r=devtools-reviewers,jdescottes

The legacy listener was explicitely avoiding emitting this event for non top-level targets.
It seems like all frontend code listening to will-navigate ignore the event is targetFront.isTopLevel is false,
so it looks like no code would expect these event.
So let's try to avoid emitting them if they aren't used by anyone.
(and can be confusing/buggy in the context of the browser toolbox)

Differential Revision: https://phabricator.services.mozilla.com/D166769
This commit is contained in:
Alexandre Poirot 2023-01-17 16:33:15 +00:00
Родитель b6a0473006
Коммит ca5f63ae6e
2 изменённых файлов: 15 добавлений и 9 удалений

Просмотреть файл

@ -120,12 +120,18 @@ class ParentProcessDocumentEventWatcher {
return;
}
// Ignore remote iframe targets which are restoring from the bfcache.
// onStateChange is called before the related target is instantiated
// and this isn't quite a navigation, we will respawn a new target.
// Only emit will-navigate for top-level targets.
if (
this.watcherActor.sessionContext.type == "all" &&
browsingContext.isContent
) {
// Never emit will-navigate for content browsing contexts in the Browser Toolbox.
// They might verify `browsingContext.top == browsingContext` because of the chrome/content
// boundary, but they do not represent a top-level target for this DevTools session.
return;
}
const isTopLevel = browsingContext.top == browsingContext;
const isRestoring = flag & Ci.nsIWebProgressListener.STATE_RESTORING;
if (!isTopLevel && isRestoring) {
if (!isTopLevel) {
return;
}

Просмотреть файл

@ -239,11 +239,11 @@ async function testIframeNavigation() {
// We are switching to a new target only when fission is enabled...
if (isFissionEnabled() || isEveryFrameTargetEnabled()) {
await waitFor(() => documentEvents.length >= 4);
await waitFor(() => documentEvents.length >= 3);
is(
documentEvents.length,
4,
"With fission/EFT, we switch to a new target and get a will-navigate followed by a new set of events: dom-loading, dom-interactive, dom-complete"
3,
"With fission/EFT, we switch to a new target and get: dom-loading, dom-interactive, dom-complete (but no will-navigate as that's only for the top BrowsingContext)"
);
const [, newIframeTarget] = await commands.targetCommand.getAllTargets([
commands.targetCommand.TYPES.FRAME,
@ -251,7 +251,7 @@ async function testIframeNavigation() {
assertEvents({
commands,
targetBeforeNavigation: iframeTarget,
documentEvents,
documentEvents: [null /* no will-navigate */, ...documentEvents],
expectedTargetFront: newIframeTarget,
expectedNewURI: secondPageUrl,
});