WebExtensions Find API - highlightResults not working anymore since FF71
Categories
(WebExtensions :: General, defect)
Tracking
(firefox72 wontfix, firefox73 wontfix, firefox74 wontfix, firefox75 fixed)
People
(Reporter: jgoudey, Unassigned)
Details
Attachments
(1 file)
641 bytes,
application/octet-stream
|
Details |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0
Steps to reproduce:
The bug was first encountered by HighlightAll extension users since FF71.
To reproduce it, the following steps can be performed.
-
Write a basic extension with just a background script.
The content of the script is as below:function highlight(results) {
if (results.count > 0) {
console.log(there are ${results.count} results
);
browser.find.highlightResults();
}
}browser.find.find("firefox", {tabId: 1, caseSensitive: false, includeRectData: false, includeRangeData: false}).then(highlight);
-
Open one tab with URL http://jgoudey.free.fr/highlightall
-
Load the extension as temporary extension from about:debugging page. Click on the button to open the debugger and debug it
Actual results:
Log entry "there are 16 results" is visible in the console (this is correct).
Error log "Error: Unable to search: 2" is displayed in the console after this first entry.
No text has been highlighted in the tab loaded with http://jgoudey.free.fr/highlightall URL
Expected results:
All 16 occurrences of "firefox" string should be highlighted.
Reporter | ||
Comment 1•6 years ago
|
||
Note: permissions "<all_urls>", "find", and "tabs" are defined in the manifest.json file of the extension
Comment 2•6 years ago
|
||
Could not reproduce on on FF 72, 73 or 74, possibly due to some syntax error found in the background script . I've attached the extension created, if you could please take a look and try yourself.
Thanks!
Reporter | ||
Comment 3•6 years ago
|
||
(In reply to Miruna Curtean from comment #2)
Created attachment 9122383 [details]
highlight API.xpiCould not reproduce on on FF 72, 73 or 74, possibly due to some syntax error found in the background script . I've attached the extension created, if you could please take a look and try yourself.
Thanks!
The string parameter in the log statement should be surrounded by backtick characters to be evaluated properly (these characters were removed by bugzilla when I reported the bug, and I can't edit the bug description):
console.log(`there are ${results.count} results`);
Comment 4•6 years ago
•
|
||
Thank you the the quick reply, Jeremy. It worked exactly as described after editing that that console.log line.
After testing on Windows 10 64-bit, MacOS Catalina 10.15 and Ubuntu VM 18.04 with FF Release 72.0.2, FF Beta 73.0b8 and FF Nightly 74.0a1 I can confirm that the "Error: Unable to search:x" error message is shown in the extension's console log and that no text has been highlighted in the loaded tab. (x value seeming to change depending on the positioning of the tab where the http://jgoudey.free.fr/highlightall URL is loaded) .
Comment 7•5 years ago
|
||
I think what is happening here is a problem with the documentation and some bad interaction with highlightResults
defaulting to the active tab.
MDN for highlightResults seems to not not document everything like the in-code docs:
@param {object} params optional - may contain any of the following properties,
all of which are optional:
{number} rangeIndex - Found range to be highlighted. Default highlights all ranges.
{number} tabId - Tab to highlight. Defaults to the active tab.
{boolean} noScroll - Don't scroll to highlighted item.
What happened for me during testing, that a call like browser.find.highlightResults()
would try to highlight on the current active tab, which in my case was about:debugging
, which is inaccessible to WebExtensions.
MDN says
Highlights the results of a previous call to find.find().
So maybe we should remember the last tabId?
Comment 8•5 years ago
|
||
Bug 1615761 seems to be a different error "no search results to highlight" unrelated to the tab-id.
Reporter | ||
Comment 9•5 years ago
|
||
Tom, I think your analysis might be right. However, the example provided here was made solely to help reproduce the bug.
But in the context of my HighlightAll extension, find and highlight actions are both performed on the current tab, and I think in the console it is indeed possible to see error "no search results to highlight" as in the related bug 1615761.
This bug should really be tested with find and highlightResults called within the same tab.
Comment 10•5 years ago
|
||
Okay, if you really see "no search results to highlight" in the console instead of "Unable to search: 2" like you said in bug 1610191 comment 0 then bug 1615761 is indeed a duplicate.
Literally calling browser.find.highlightResults()
, without any parameters will always fail at the moment. Bug 1615761 should fix that.
I also updated https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/find/highlightResults
Updated•5 years ago
|
Updated•5 years ago
|
Description
•