Closed Bug 250715 Opened 21 years ago Closed 20 years ago

Opening a third-party sidebar throws a JS error

Categories

(Firefox :: General, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

VERIFIED DUPLICATE of bug 271022

People

(Reporter: asqueella, Assigned: bugzilla)

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040708 Firefox/0.9.0+ (best browser EVAR1!!) Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040708 Firefox/0.9.0+ When I open a third-party sidebar in Firefox, I get this error: Error: searchBox has no properties Source File: chrome://browser/content/browser.js Line: 3009 browser.js: > if (aCommandID != "viewWebPanelsSidebar") { // no searchbox there > // if the sidebar we want is already constructed, focus the searchbox > if ((aCommandID == "viewBookmarksSidebar" && sidebar.contentDocument.getElementById("bookmarksPanel")) > || (aCommandID == "viewHistorySidebar" && sidebar.contentDocument.getElementById("history-panel"))) > sidebar.contentDocument.getElementById("search-box").focus(); > // otherwiese, attach an onload handler > else > sidebar.addEventListener("load", asyncFocusSearchBox, true); > } Reproducible: Always Steps to Reproduce: 1. Install QuickNote 2. Open QN in sidebar Actual Results: an error in JS Console Expected Results: no error I've seen this problem with QuickNote and Sage. As far as I can tell, the cause of this error is that the code above assumes that there are only three sidebars - viewWebPanelsSidebar, viewBookmarksSidebar and viewHistorySidebar, which is wrong. The solution is to use ((aCommandID == "viewBookmarksSidebar") || (aCommandID == "viewHistorySidebar")) instead.
This JavaScript-error occurs in every sidebar without the expected textbox. Perhaps the better solution would be to check simply if there is an element named 'search-box', instead of the proposed one by Nickolay. So Firefox could support even third-party sidebars (i.e. focus the search box). (In Firefox 1.0 it seems to be line# 3330)
Status: UNCONFIRMED → NEW
Ever confirmed: true
I suggest creating a new attribute: "autoactivateid" with the name of the element to focus. Or "onactivate" with javascript code. function asyncOnActivate(event) // blindwritten: may contain errors { var sidebar = document.getElementById("sidebar"); sidebar.removeEventListener("load", asyncOnActivate, true); // do first // element id case var toFocus = sidebar.getAttribute("autoactivateid"); if(toFocus && toFocus.length) { try { var elem=sidebar.contentDocument.getElementById(toFocus); if(elem) elem.focus(); } catch(e) {} // script case var toScript = sidebar.getAttribute("onactivate"); if(toScript && toScript.length) { (new Function(event, toScript))(event); } } if not at least this should be done: function asyncFocusSearchBox(event) { var sidebar = document.getElementById("sidebar"); try { var searchBox = sidebar.contentDocument.getElementById("search-box"); searchBox.focus(); } catch(e) {} sidebar.removeEventListener("load", asyncFocusSearchBox, true); }
How about the 1-line fix so hopefully this can make it into 1.5: if (searchBox) searchBox.focus();
*** This bug has been marked as a duplicate of 271022 ***
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.