Closed Bug 1663904 Opened 5 years ago Closed 5 years ago

Using Global Search bar logs error: TypeError: can't access property "hasAttribute", window.gBrowser.selectedBrowser is null

Categories

(Thunderbird :: Search, defect)

Thunderbird 82
defect

Tracking

(thunderbird_esr78 unaffected, thunderbird82 affected)

RESOLVED FIXED
83 Branch
Tracking Status
thunderbird_esr78 --- unaffected
thunderbird82 --- affected

People

(Reporter: lasana, Assigned: lasana)

References

(Regression)

Details

Attachments

(1 file, 1 obsolete file)

STR

  • Enter a search term in the global search bar.
  • Hit enter key.
  • Open console:

Expected Result:
Search results should show with no errors in console.

Actual Result:
Search works but the following trace is observed:

Uncaught TypeError: can't access property "hasAttribute", window.gBrowser.selectedBrowser is null
    AutocompleteInput chrome://global/content/elements/autocomplete-input.js:70
    openTab chrome://messenger/content/glodaFacetTab.js:36
    openTab chrome://messenger/content/tabmail.js:959
    doSearch chrome://messenger/content/gloda-autocomplete-input.js:217
    MozGlodaAutocompleteInput chrome://messenger/content/gloda-autocomplete-input.js:60

I came across this while working on bug 1658227.

This does not appear to affect 78 though I have been unable so far to determine the difference between it and 82.

The error happens when the focus() method is called here https://searchfox.org/comm-central/source/mail/base/content/glodaFacetTab.js#36, it prematurely causes the "focus" event listener in autocomplete-input to be fired before the tab's browser property is properly initialized.
https://searchfox.org/mozilla-central/source/toolkit/content/widgets/autocomplete-input.js#64

This does not seem to happen on prior versions as far as I can tell.

Looks like this error got introduced with this commit. It sets the global gBrowser property to tabmail causing the second part of the if condition in autocomplete-input to be evaluated (window.gBrowser would have been undefined previously).

https://hg.mozilla.org/comm-central/rev/08e8b872695145ef325df8fee38139517d3f1be2#l3.30

Attached patch 1663904.patch (obsolete) — Splinter Review

I moved the call to focus() into the xulLoadHandler(). That way the browser is not null when autocomplete-input does its checks.

Assignee: nobody → lasana
Attachment #9180233 - Flags: review?(mkmelin+mozilla)
Status: NEW → ASSIGNED
Comment on attachment 9180233 [details] [diff] [review] 1663904.patch Review of attachment 9180233 [details] [diff] [review]: ----------------------------------------------------------------- ::: mail/test/browser/global-search-bar/browser_global-search-bar.js @@ +10,5 @@ > + let errorThrown = false; > + let searchInput = window.document.querySelector("#searchInput"); > + > + window.addEventListener("error", e => { > + if (e.message.includes("window.gBrowser.selectedBrowser is null")) { why restrict it to this specific error?

(In reply to Magnus Melin [:mkmelin] from comment #6)

Comment on attachment 9180233 [details] [diff] [review]
1663904.patch

Review of attachment 9180233 [details] [diff] [review]:

::: mail/test/browser/global-search-bar/browser_global-search-bar.js
@@ +10,5 @@

  • let errorThrown = false;
  • let searchInput = window.document.querySelector("#searchInput");
  • window.addEventListener("error", e => {
  • if (e.message.includes("window.gBrowser.selectedBrowser is null")) {

why restrict it to this specific error?

I figure it's better to be specific here in case any future bugs mislead us into thinking this bug has regressed.

Comment on attachment 9180233 [details] [diff] [review] 1663904.patch Review of attachment 9180233 [details] [diff] [review]: ----------------------------------------------------------------- The naming convention for mochitests are like browser_glodaSearchTab.js ::: mail/test/browser/global-search-bar/browser_global-search-bar.js @@ +10,5 @@ > + let errorThrown = false; > + let searchInput = window.document.querySelector("#searchInput"); > + > + window.addEventListener("error", e => { > + if (e.message.includes("window.gBrowser.selectedBrowser is null")) { In general we test for effects, not that certain errors aren't thrown. And if you restrict checking to only this error, any other future errors would go unnoticed. Maybe test that the focusing succeeded instead, (document.activeElement is the search input)? @@ +19,5 @@ > + searchInput.value = "Bugzilla"; > + EventUtils.synthesizeMouseAtCenter(searchInput, {}, window); > + EventUtils.synthesizeKey("VK_RETURN", {}, window); > + > + Assert.ok(!errorThrown, "using global search did no throw an error"); Unfortunately I don't think you can trust that the key press had time to cause any effects just yet. That is, the error listener may not yet have been invoked when you check this. If you try ./mach test --verify it will also fail
Attachment #9180233 - Flags: review?(mkmelin+mozilla)
Attached patch 1663904v2.patchSplinter Review

Changed the test to check the searchInput has focus. Added a cleanup function so --verify works.

Attachment #9180233 - Attachment is obsolete: true
Attachment #9180469 - Flags: review?(mkmelin+mozilla)
Comment on attachment 9180469 [details] [diff] [review] 1663904v2.patch Review of attachment 9180469 [details] [diff] [review]: ----------------------------------------------------------------- Looks great, thx! r=mkmelin
Attachment #9180469 - Flags: review?(mkmelin+mozilla) → review+
Target Milestone: --- → 83 Branch

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/f56b81827087
Focus global search input after browser has been loaded. r=mkmelin DONTBUILD

Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Regressions: 1679113
See Also: → 1680587
Regressed by: 810815
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: