| Bug 2038882: Keep urlbar results open when opening a result in a background tab
Authored by daisuke on May 12 2026, 7:10 AM. Referenced Files | Unknown Object (File) | | Tue, Jun 16, 10:07 PM2026-06-16 22:07:58 (UTC+0) |
| Unknown Object (File) | | Tue, Jun 16, 10:07 PM2026-06-16 22:07:58 (UTC+0) |
| Unknown Object (File) | | Tue, Jun 16, 10:07 PM2026-06-16 22:07:57 (UTC+0) |
| Unknown Object (File) | | Wed, Jun 10, 5:49 AM2026-06-10 05:49:23 (UTC+0) |
| Unknown Object (File) | | Tue, Jun 2, 4:17 AM2026-06-02 04:17:05 (UTC+0) |
| Unknown Object (File) | | Mon, Jun 1, 5:44 AM2026-06-01 05:44:10 (UTC+0) |
| Unknown Object (File) | | Mon, Jun 1, 5:44 AM2026-06-01 05:44:10 (UTC+0) |
Event Timelinedao 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.) |
| 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! |
dao added inline comments. | browser/components/urlbar/content/UrlbarInput.mjs |
| 1614–1615 | |
| 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? |
| 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. |
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 | |
Comment ActionsThis 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 ActionsThank 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 ActionsThe 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 ActionsThanks Daisuke. This is an interesting approach that I hadn't considered. There are two different aspects that are interesting to me:
- The view is closed after the page load rather than before, if the load is in the foreground
- 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 ActionsThank 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:
- The view is closed after the page load rather than before, if the load is in the foreground
- 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
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.
- For blank page. We can detect it in the function though. (e.g. about:newtab expects to keep the focus on the urlbar)
- 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).
- 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 ActionsOK, 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 ActionsThank you very much, Drew!
Okay, I will make a common function and use it. | 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 |
Comment ActionsThank 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. |
Comment ActionsThanks 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 | |
| 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. |
Comment ActionsOther 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 | |
Comment ActionsThank 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 | |
| browser/modules/URILoadingHelper.sys.mjs |
| 386–388 | |
| toolkit/modules/BrowserUtils.sys.mjs |
| 678 | |
| toolkit/modules/tests/xpcshell/test_BrowserUtils.js |
| 748 | Oops, I had forgotten to update to use here.. |
This revision was automatically updated to reflect the committed changes. | Path | Size |
|---|
| | | | 35 lines | | | 2 lines | | | 17 lines | | | 35 lines | | | 146 lines |
| Commit | Tree | Parents | Author | Summary | Date |
|---|
| 8d7c331c3fa2 | d1d37f541dff | Daisuke Akatsuka | Bug 2038882: Keep urlbar results open when opening a result in a background tab… (Show More…) |
- Thu, Jun 18, 1:47 AM2026-06-18 01:47:44 (UTC+0)
- Wed, Jun 17, 6:25 PM2026-06-17 18:25:15 (UTC+0)
- Wed, Jun 17, 4:40 PM2026-06-17 16:40:54 (UTC+0)
- Wed, Jun 17, 3:06 PM2026-06-17 15:06:42 (UTC+0)
- Wed, Jun 17, 2:10 PM2026-06-17 14:10:10 (UTC+0)
- Mon, Jun 15, 7:38 PM2026-06-15 19:38:00 (UTC+0)
- Mon, Jun 15, 3:37 PM2026-06-15 15:37:44 (UTC+0)
- Mon, Jun 15, 11:54 AM2026-06-15 11:54:51 (UTC+0)
- Fri, Jun 12, 2:45 PM2026-06-12 14:45:45 (UTC+0)
- Thu, Jun 11, 4:53 PM2026-06-11 16:53:09 (UTC+0)
browser/components/urlbar/content/UrlbarInput.mjsbrowser/components/urlbar/tests/browser/browser_locationBarCommand.jsbrowser/modules/URILoadingHelper.sys.mjstoolkit/modules/BrowserUtils.sys.mjstoolkit/modules/tests/xpcshell/test_BrowserUtils.js |