VOOZH about

URL: https://phabricator.services.mozilla.com/D299948

⇱ ⚙ D299948 Bug 2038882: Keep urlbar results open when opening a result in a background tab


Bug 2038882: Keep urlbar results open when opening a result in a background tab
ClosedPublic

Authored by daisuke on May 12 2026, 7:10 AM.
Referenced Files
F72921690: D299948.1781793433.diff
Wed, Jun 17, 2:37 PM
Unknown Object (File)
Tue, Jun 16, 10:07 PM
Unknown Object (File)
Tue, Jun 16, 10:07 PM
Unknown Object (File)
Tue, Jun 16, 10:07 PM
Unknown Object (File)
Wed, Jun 10, 5:49 AM
Unknown Object (File)
Tue, Jun 2, 4:17 AM
Unknown Object (File)
Mon, Jun 1, 5:44 AM
Unknown Object (File)
Mon, Jun 1, 5:44 AM
Subscribers

Diff Detail

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
dao requested changes to this revision.May 12 2026, 9:57 AM
dao added a subscriber: dao.
dao added inline comments.
browser/components/urlbar/content/UrlbarInput.mjs
1626–1632

Why is a thing? These parameters are for methods which don't seem to know about this one.

Could this just be inferred from instead of having another new flag? Alternatively, should this be an argument or option for ? (Side note: I'd also suggest renaming this to or so.)

This revision now requires changes to proceed.May 12 2026, 9:57 AM
browser/components/urlbar/content/UrlbarInput.mjs
1626–1632

The flag named describes how the URL is opened, and it is used at many places (For , we pass the flag from only one place though). So, I thought it should not change the urlbar view behavior. So I added flag separately.

Side note: I'd also suggest renaming this to keepViewOpen or so.

Thanks! I will rename to that!

daisuke updated this revision to Diff 1272571.
dao requested changes to this revision.May 12 2026, 2:20 PM
dao added inline comments.
browser/components/urlbar/content/UrlbarInput.mjs
1614–1615

Unfortunately we don't have a type definition for this yet, but please do not set this on since the purpose of that object is to be passed to . Here's its loose definition: https://searchfox.org/firefox-main/rev/c001029846a51b9e15898d0900ef0c7cafb55b26/browser/modules/URILoadingHelper.sys.mjs#364-459

If you don't want to overload , just have take another argument?

1626–1632

The flag named describes how the URL is opened, and it is used at many places (For , we pass the flag from only one place though). So, I thought it should not change the urlbar view behavior. So I added flag separately.

When urlbar code is setting , even if that's primarily for purposes, I think it would be fine for urlbar code to also look at that at a later point and make decisions based on that. Perhaps the crucial question is, is there a scenario where opens a background tab and would not want the view to stay open?

This revision now requires changes to proceed.May 12 2026, 2:20 PM
browser/components/urlbar/content/UrlbarInput.mjs
1626–1632

Indeed, there might not be a case. I change my mind, I'll use the flag as is. When needed, we shall add the such flag.

daisuke updated this revision to Diff 1273252.
dao added inline comments.
browser/components/urlbar/content/UrlbarInput.mjs
4365–4366

nit: move this comment into the if-branch?

browser/components/urlbar/content/UrlbarInput.mjs
4365–4366

Okay, thanks!

Comment Actions

This seems to affect only clicks using the new context menu since that's the only path that sets afaict. Is that intentional?

There are other ways to open tabs in the bg from the urlbar. Rather than using , they rely on returning or as appropriate plus the existing logic in openLinkIn, which checks the browser.tabs.loadInBackground pref.

If it is intentional, I'd like to make that more explicit, for example by adding a comment at least. If it's not intentional, then I think this needs some more work to support those other cases.

Comment Actions

Thank you very much, Drew!

This seems to affect only clicks using the new context menu since that's the only path that sets afaict. Is that intentional?

There are other ways to open tabs in the bg from the urlbar. Rather than using , they rely on returning or as appropriate plus the existing logic in openLinkIn, which checks the browser.tabs.loadInBackground pref.

If it is intentional, I'd like to make that more explicit, for example by adding a comment at least. If it's not intentional, then I think this needs some more work to support those other cases.

Oh, sorry, yeah, you are right! I completely missed that. I will address it. Thanks!

Comment Actions

The main updates:

  • Since we don't know a place where opening url at unless opening actually via openLinkIn(), get to know it using . And, do closing processing in the callback.
  • To avoid extra processing to load URL, added .
  • Since the timing of view closing and urlbar blurring, changes a bit.
Comment Actions

Thanks Daisuke. This is an interesting approach that I hadn't considered. There are two different aspects that are interesting to me:

  1. The view is closed after the page load rather than before, if the load is in the foreground
  2. is used to do it

I think point 1 is perfectly valid. The drawback is that it's a substantial change from how the urlbar currently works. The page-load process is already pretty complex and is spread across multiple parts of the codebase, not only urlbar. I'm worried that this change might interact with that process in surprising ways. You mentioned . Have you run this patch on try? If there aren't any significant failures, that would give me some confidence.

But I'd like to ask you to consider two other approaches that I think are simpler. Let me know what you think:

(1) The logic in that determines whether the load should happen in the background is a small number of lines: https://searchfox.org/firefox-main/rev/2bd78d82d0128abc12df9900b6cb264f92adb9d0/browser/modules/URILoadingHelper.sys.mjs#542,544,574-582,596-597

If that logic were made available to callers somehow, it would let you decide whether the view should be closed, right? There are a few ways to do that:

  • Factor it out into a new helper function that both and would call
  • Modify and all the similar open-link functions it so that they take an out-param that tells callers whether the load happened in the background
  • Even just copy-paste the logic into a helper method that you could call

This would let us keep the logic substantially unchanged.

(2) Point 1 (closing the view after the load) is valid, to reiterate. Point 2 (using ) made me think about how the urlbar currently handles page loads.

already has a method that's called when a page is loaded in the foreground: . Rather than use to add yet another code path that runs on page load, it would be simpler to use the existing one in .

That's easier said than done of course. is called in cases other than page loads, like switching tabs. It has some params that tell you whether a page loaded.

There are other places in you'd need to modify besides . For example focuses the content browser, reverts the input, and closes the view, so you'd need to change that so it doesn't happen until is called.

I tried commenting out all those lines in and simply calling in , and it worked surprisingly well. For example something focused the content browser after the view closed even though I didn't add any lines to do it. That illustrates what I mean about the page-load process being complex. If we take this approach, it could be the start of a larger project of simplification and refactoring IMO.

Comment Actions

Thank you very much for your review, Drew!

Thanks Daisuke. This is an interesting approach that I hadn't considered. There are two different aspects that are interesting to me:

  1. The view is closed after the page load rather than before, if the load is in the foreground
  2. is used to do it

I think point 1 is perfectly valid. The drawback is that it's a substantial change from how the urlbar currently works. The page-load process is already pretty complex and is spread across multiple parts of the codebase, not only urlbar. I'm worried that this change might interact with that process in surprising ways. You mentioned . Have you run this patch on try? If there aren't any significant failures, that would give me some confidence.

Yes, it seems no issues.
https://treeherder.mozilla.org/jobs?repo=try&selectedTaskRun=dvm8o2WOSAKPt8ukcvCQbQ.0&resultStatus=testfailed%2Cbusted%2Cexception%2Csuccess%2Cretry%2Cusercancel%2Crunnable&revision=5d832678691454a3a8103bbb6cd8e58522609c6d

But I'd like to ask you to consider two other approaches that I think are simpler. Let me know what you think:

(1) The logic in that determines whether the load should happen in the background is a small number of lines: https://searchfox.org/firefox-main/rev/2bd78d82d0128abc12df9900b6cb264f92adb9d0/browser/modules/URILoadingHelper.sys.mjs#542,544,574-582,596-597

If that logic were made available to callers somehow, it would let you decide whether the view should be closed, right? There are a few ways to do that:

  • Factor it out into a new helper function that both and would call
  • Modify and all the similar open-link functions it so that they take an out-param that tells callers whether the load happened in the background
  • Even just copy-paste the logic into a helper method that you could call

This would let us keep the logic substantially unchanged.

I thought this way at first though, even if we make a shared function, there is possibility to change the state in the middle, I wanted to believe the result.

(2) Point 1 (closing the view after the load) is valid, to reiterate. Point 2 (using ) made me think about how the urlbar currently handles page loads.

already has a method that's called when a page is loaded in the foreground: . Rather than use to add yet another code path that runs on page load, it would be simpler to use the existing one in .

That's easier said than done of course. is called in cases other than page loads, like switching tabs. It has some params that tell you whether a page loaded.

There are other places in you'd need to modify besides . For example focuses the content browser, reverts the input, and closes the view, so you'd need to change that so it doesn't happen until is called.

I tried commenting out all those lines in and simply calling in , and it worked surprisingly well. For example something focused the content browser after the view closed even though I didn't add any lines to do it. That illustrates what I mean about the page-load process being complex. If we take this approach, it could be the start of a larger project of simplification and refactoring IMO.

Yeah, super interesting. I want to try this one, thanks!

Comment Actions

There are some failures in the try run.
https://treeherder.mozilla.org/jobs?repo=try&selectedTaskRun=G_j7g5YCQgu_EogKPvgBoA.0&resultStatus=testfailed%2Cbusted%2Cexception%2Csuccess%2Cretry%2Cusercancel%2Crunnable&revision=0fd6836039b05dc9772acd49660f61b9fa006f40
I will investigate them. I suspect one of the causes is the component. With this patch, the focus behavior of will change (e.g. Shift+Alt+Click on the button). I'd like your opinion on whether we should apply the same focus logic to all components as well. @adw

Comment Actions

There are some failures in the try run.
https://treeherder.mozilla.org/jobs?repo=try&selectedTaskRun=G_j7g5YCQgu_EogKPvgBoA.0&resultStatus=testfailed%2Cbusted%2Cexception%2Csuccess%2Cretry%2Cusercancel%2Crunnable&revision=0fd6836039b05dc9772acd49660f61b9fa006f40
I will investigate them. I suspect one of the causes is the component. With this patch, the focus behavior of will change (e.g. Shift+Alt+Click on the button). I'd like your opinion on whether we should apply the same focus logic to all components as well. @adw

Hmm, doing it in seems like it might be more complex than we expected. We need to add special handling for the following cases, I think.

  1. For blank page. We can detect it in the function though. (e.g. about:newtab expects to keep the focus on the urlbar)
  2. For since the focus behavior after clicking differs from choosing urlbar result. However, we can't know how the setURI() was called in there, it might be difficult and might need a flag in the class (but a bit naive I think).
  3. There are other ways to open uri such as browser.fixupAndLoadURIString(). It seems like this expects keeping the focus on the urlbar even if opening a actual url. I am not sure we can change the focus behavior now..

So, we might be better to revert to the previous revision.. What do you think?

Comment Actions

OK, thanks for trying.

I thought this way at first though, even if we make a shared function, there is possibility to change the state in the middle, I wanted to believe the result.

Could you elaborate on this? To me, if we could keep the behavior and timings the same as they are now (aside from keeping the view open in these new cases), that would be the better outcome at this point. Much less risk for regressions and unintended consequences, although it's good that your try push didn't have any failures.

Comment Actions

Thank you very much, Drew!
Okay, I will make a common function and use it.

daisuke updated this revision to Diff 1293478.
Comment Actions

The changes are new since I looked at this, so I'm tagging firefox-desktop-core-reviewers for an additional review.

mossop requested changes to this revision.Mon, Jun 8, 12:59 PM
mossop added a subscriber: mossop.
mossop added inline comments.
browser/components/urlbar/content/UrlbarInput.mjs
1630–1633

This feels very clunky and the cost of resolving is extremely low, can we just leave this out?

toolkit/modules/BrowserUtils.sys.mjs
679–682

Since is a required argument I think it makes sense to match the signature of here.

679–698

I would like to see an automated test verifying this function

This revision now requires changes to proceed.Mon, Jun 8, 12:59 PM
Comment Actions

Thank you very much, @mossop!
I will address your comments.

browser/components/urlbar/content/UrlbarInput.mjs
1630–1633

Yeah, I understand. I tried to implement without such a flag, but I couldn't come up with a good idea.

treats a non-null as a base value that the case still inverts — callers like the downloads code and rely on this (they pass a pref-derived and expect Shift to flip it). In the urlbar we've already resolved the final value here (including the inversion), so if resolves again it inverts a second time and opens in the wrong foreground/background. just tells the value is final.

That said, I've thought of one approach, though it might make the code a little weaker. That does not set flag here. I'll give it a try.

browser/components/urlbar/content/UrlbarInput.mjs
1630–1633

Ah, no, we need to set flag at least in case of the context menu.. Let me think again.

browser/components/urlbar/content/UrlbarInput.mjs
1630–1633

We may solve using flag. I will give it a try.

daisuke updated this revision to Diff 1295856.
Comment Actions

Thanks for all your work on this. I'll r+ for urlbar but the other changes lgtm too.

browser/components/urlbar/content/UrlbarInput.mjs
1623

Could you help me understand why this works? I tried to follow the path but couldn't figure it out. The param is called , and you're setting it to true, so every new tab should load in the foreground, but it doesn't -- it works as it should. How?

4284
browser/modules/URILoadingHelper.sys.mjs
386–388

Can be removed I think?

toolkit/modules/BrowserUtils.sys.mjs
678

Naming nit: is a little better IMO since, as the jsdoc says, it's whether the link will load in the background, not "should" it. I defer to @mossop though if he disagrees.

693–695

Style nit: I would move to the bottom of the method, outside the , so that the method always has an obvious return value.

mossop added a project: testing-approved.
Comment Actions

Other than the question about ignoring the pref this looks fine

browser/components/urlbar/content/UrlbarInput.mjs
1623

causes us to ignore the value of the preference, it will cause to load in the foreground and to load in the background. Do we actually want to ignore the pref here though?

toolkit/modules/BrowserUtils.sys.mjs
678

I agree

This revision is now accepted and ready to land.Wed, Jun 10, 12:18 PM
Comment Actions

Thank you very much for the review!

browser/components/urlbar/content/UrlbarInput.mjs
1623

This is to match the existing behavior. Urlbar result loads go through , which already does params.forceForeground ??= true, so urlbar picks have always ignored . Setting explicitly here just keeps the value consistent with how the load will actually behave.

4284

Thanks!

browser/modules/URILoadingHelper.sys.mjs
386–388

Oops, yes.

toolkit/modules/BrowserUtils.sys.mjs
678

Okay, thank you so much!

toolkit/modules/tests/xpcshell/test_BrowserUtils.js
748

Oops, I had forgotten to update to use here..

Revision Contents

PathSize
browser/
components/
urlbar/
content/
35 lines
tests/
browser/
2 lines
modules/
17 lines
toolkit/
modules/
35 lines
tests/
xpcshell/
146 lines
CommitTreeParentsAuthorSummaryDate
8d7c331c3fa2d1d37f541dffDaisuke Akatsuka
Bug 2038882: Keep urlbar results open when opening a result in a background tab… (Show More…)

Diff 1297087

browser/components/urlbar/content/UrlbarInput.mjs

Loading...

browser/components/urlbar/tests/browser/browser_locationBarCommand.js

Loading...

browser/modules/URILoadingHelper.sys.mjs

Loading...

toolkit/modules/BrowserUtils.sys.mjs

Loading...

toolkit/modules/tests/xpcshell/test_BrowserUtils.js

Loading...