From 6dfeba05d16b9ce4ade367bfba4bd7e2f1645625 Mon Sep 17 00:00:00 2001 From: ownedbywuigi Date: Wed, 1 Apr 2026 16:33:21 +0100 Subject: [PATCH] Fix bug where search bar in about:home does nothing --- .../base/content/abouthome/aboutHome.css | 1 + .../base/content/abouthome/aboutHome.js | 35 +++++++++++++-- .../base/content/abouthome/aboutHome.xhtml | 2 +- .../basilisk/base/content/tab-content.js | 45 +++++++++++++++++-- .../basilisk/base/content/utilityOverlay.js | 2 +- .../components/newtab/aboutNewTabService.js | 2 +- application/basilisk/modules/AboutHome.jsm | 26 +++++++++++ 7 files changed, 104 insertions(+), 9 deletions(-) diff --git a/application/basilisk/base/content/abouthome/aboutHome.css b/application/basilisk/base/content/abouthome/aboutHome.css index 5767066670..62a3ac6d64 100644 --- a/application/basilisk/base/content/abouthome/aboutHome.css +++ b/application/basilisk/base/content/abouthome/aboutHome.css @@ -120,6 +120,7 @@ a { transition-property: background-color, border-color, box-shadow; transition-duration: 150ms; width: 50px; + display: none; } #searchSubmit:dir(rtl) { diff --git a/application/basilisk/base/content/abouthome/aboutHome.js b/application/basilisk/base/content/abouthome/aboutHome.js index 0cbcc835a4..2be5da2a24 100644 --- a/application/basilisk/base/content/abouthome/aboutHome.js +++ b/application/basilisk/base/content/abouthome/aboutHome.js @@ -27,7 +27,10 @@ window.addEventListener("pageshow", function () { // Delay search engine setup, cause browser.js::BrowserOnAboutPageLoad runs // later and may use asynchronous getters. window.gObserver.observe(document.documentElement, { attributes: true }); - window.gObserver.observe(document.getElementById("launcher"), { attributes: true }); + let launcher = document.getElementById("launcher"); + if (launcher) { + window.gObserver.observe(launcher, { attributes: true }); + } fitToWidth(); setupSearch(); window.addEventListener("resize", fitToWidth); @@ -72,7 +75,22 @@ window.addEventListener("keypress", ev => { function onSearchSubmit(aEvent) { - gContentSearchController.search(aEvent); + if (aEvent instanceof MouseEvent && gContentSearchController && + gContentSearchController.defaultEngine) { + gContentSearchController.search(aEvent); + return; + } + + // Fallback path for builds where ContentSearch mediation fails. + let terms = searchText && searchText.value ? searchText.value.trim() : ""; + if (!terms) { + return; + } + + document.dispatchEvent(new CustomEvent("AboutHomeSearch", { + bubbles: true, + detail: { searchString: terms }, + })); } @@ -80,10 +98,13 @@ var gContentSearchController; function setupSearch() { + let searchSubmit = document.getElementById("searchSubmit"); + // Set submit button label for when CSS background are disabled (e.g. // high contrast mode). - document.getElementById("searchSubmit").value = + searchSubmit.value = document.body.getAttribute("dir") == "ltr" ? "\u25B6" : "\u25C0"; + searchSubmit.addEventListener("click", onSearchSubmit, true); // The "autofocus" attribute doesn't focus the form element // immediately when the element is first drawn, so the @@ -99,6 +120,14 @@ function setupSearch() new ContentSearchUIController(searchText, searchText.parentNode, "abouthome", "homepage"); } + + searchText.addEventListener("keypress", function(event) { + if (event.keyCode == event.DOM_VK_RETURN) { + event.preventDefault(); + event.stopPropagation(); + onSearchSubmit(event); + } + }, true); } /** diff --git a/application/basilisk/base/content/abouthome/aboutHome.xhtml b/application/basilisk/base/content/abouthome/aboutHome.xhtml index 588e9b2bee..4b43548ddb 100644 --- a/application/basilisk/base/content/abouthome/aboutHome.xhtml +++ b/application/basilisk/base/content/abouthome/aboutHome.xhtml @@ -42,7 +42,7 @@
-
diff --git a/application/basilisk/base/content/tab-content.js b/application/basilisk/base/content/tab-content.js index c32acbcccb..fd4612cc4d 100644 --- a/application/basilisk/base/content/tab-content.js +++ b/application/basilisk/base/content/tab-content.js @@ -82,10 +82,22 @@ addMessageListener("MixedContent:ReenableProtection", function() { var AboutHomeListener = { init: function(chromeGlobal) { chromeGlobal.addEventListener('AboutHomeLoad', this, false, true); + chromeGlobal.addEventListener('AboutHomeSearch', this, false, true); + }, + + _isAboutHomeDocumentURI(uri) { + if (!uri) { + return false; + } + let lowerURI = uri.toLowerCase(); + return lowerURI == "about:home" || + lowerURI.startsWith("about:home?") || + lowerURI.startsWith("about:home#") || + lowerURI == "chrome://browser/content/abouthome/abouthome.xhtml"; }, get isAboutHome() { - return content.document.documentURI.toLowerCase() == "about:home"; + return this._isAboutHomeDocumentURI(content.document.documentURI); }, handleEvent: function(aEvent) { @@ -96,6 +108,9 @@ var AboutHomeListener = { case "AboutHomeLoad": this.onPageLoad(); break; + case "AboutHomeSearch": + this.onSearch(aEvent); + break; case "click": this.onClick(aEvent); break; @@ -144,7 +159,7 @@ var AboutHomeListener = { let originalTarget = aEvent.originalTarget; let ownerDoc = originalTarget.ownerDocument; - if (ownerDoc.documentURI != "about:home") { + if (!this._isAboutHomeDocumentURI(ownerDoc.documentURI)) { // This shouldn't happen, but we're being defensive. return; } @@ -191,6 +206,25 @@ var AboutHomeListener = { removeEventListener("click", this, true); removeEventListener("pagehide", this, true); }, + + onSearch: function(aEvent) { + let originalTarget = aEvent.originalTarget || aEvent.target; + let ownerDoc = originalTarget && originalTarget.ownerDocument; + if (!ownerDoc && originalTarget && originalTarget.nodeType == Ci.nsIDOMNode.DOCUMENT_NODE) { + ownerDoc = originalTarget; + } + if (!ownerDoc || !this._isAboutHomeDocumentURI(ownerDoc.documentURI)) { + return; + } + + let detail = aEvent.detail || {}; + let searchString = (detail.searchString || "").trim(); + if (!searchString) { + return; + } + + sendAsyncMessage("AboutHome:Search", { searchString }); + }, }; AboutHomeListener.init(this); @@ -362,6 +396,7 @@ var ContentSearchMediator = { whitelist: new Set([ "about:home", "about:newtab", + "chrome://browser/content/abouthome/aboutHome.xhtml", ]), init: function (chromeGlobal) { @@ -389,7 +424,11 @@ var ContentSearchMediator = { }, get _contentWhitelisted() { - return this.whitelist.has(content.document.documentURI); + let documentURI = content.document.documentURI; + // about:home may carry query/hash fragments; whitelist should apply to the + // base page URI so search events are not dropped for those variants. + let baseURI = documentURI.replace(/[?#].*$/, ""); + return this.whitelist.has(baseURI); }, _sendMsg: function (type, data=null) { diff --git a/application/basilisk/base/content/utilityOverlay.js b/application/basilisk/base/content/utilityOverlay.js index f355179cb5..fa2ebeb0a4 100644 --- a/application/basilisk/base/content/utilityOverlay.js +++ b/application/basilisk/base/content/utilityOverlay.js @@ -27,7 +27,7 @@ this.__defineGetter__("BROWSER_NEW_TAB_URL", () => { !aboutNewTabService.overridden) { return "about:privatebrowsing"; } - return aboutNewTabService.newTabURL; + return "about:home"; }); var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab"; diff --git a/application/basilisk/components/newtab/aboutNewTabService.js b/application/basilisk/components/newtab/aboutNewTabService.js index 54c3749e88..ad63eeec63 100644 --- a/application/basilisk/components/newtab/aboutNewTabService.js +++ b/application/basilisk/components/newtab/aboutNewTabService.js @@ -27,7 +27,7 @@ const LOCAL_NEWTAB_URL = "chrome://browser/content/newtab/newTab.xhtml"; const REMOTE_NEWTAB_PATH = "/newtab/v%VERSION%/%CHANNEL%/%LOCALE%/index.html"; -const ABOUT_URL = "about:newtab"; +const ABOUT_URL = "about:home"; // Pref that tells if remote newtab is enabled const PREF_REMOTE_ENABLED = "browser.newtabpage.remote"; diff --git a/application/basilisk/modules/AboutHome.jsm b/application/basilisk/modules/AboutHome.jsm index 671448480b..a68ad2ab66 100644 --- a/application/basilisk/modules/AboutHome.jsm +++ b/application/basilisk/modules/AboutHome.jsm @@ -81,6 +81,7 @@ var AboutHome = { "AboutHome:Addons", "AboutHome:Sync", "AboutHome:Settings", + "AboutHome:Search", "AboutHome:RequestUpdate", "AboutHome:MaybeShowAutoMigrationUndoNotification", ], @@ -129,6 +130,31 @@ var AboutHome = { window.openPreferences(); break; + case "AboutHome:Search": { + let data = aMessage.data || {}; + let searchString = (data.searchString || "").trim(); + if (!searchString) { + break; + } + + let engine = Services.search.defaultEngine; + if (!engine) { + break; + } + + let submission = engine.getSubmission(searchString, "", "homepage"); + if (!submission) { + break; + } + + aMessage.target.loadURIWithFlags(submission.uri.spec, + Ci.nsIWebNavigation.LOAD_FLAGS_NONE, + null, + null, + submission.postData); + break; + } + case "AboutHome:RequestUpdate": this.sendAboutHomeData(aMessage.target); break;