browser.find.highlightResults() does not work properly
Categories
(WebExtensions :: General, defect)
Tracking
(firefox-esr68 unaffected, firefox73 wontfix, firefox74 wontfix, firefox75 fixed)
Tracking | Status | |
---|---|---|
firefox-esr68 | --- | unaffected |
firefox73 | --- | wontfix |
firefox74 | --- | wontfix |
firefox75 | --- | fixed |
People
(Reporter: iamtonylee, Assigned: evilpie)
References
(Regression)
Details
(Keywords: regression)
Attachments
(1 file)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:72.0) Gecko/20100101 Firefox/72.0
Steps to reproduce:
- Create a minimal extension with these code:
highlight.js:
{
"description": "Highlight Selected",
"manifest_version": 2,
"name": "Highlight Selected",
"version": "1.0",
"icons": {
"48": "icons/border-48.png"
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"background",
"find"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["highlight.js"]
}
]
}
highlight.js:
let lastSelectedText = '';
document.addEventListener('dblclick', (evt) => {
console.log('dblclick --', lastSelectedText);
browser.runtime.sendMessage({
action: 'highlight',
selectedText: lastSelectedText
});
});
document.addEventListener('selectionchange', (evt) => {
const selection = document.getSelection();
if (selection.isCollapsed) {
lastSelectedText = '';
} else {
const selectedText = selection.toString();
lastSelectedText = selectedText;
}
});
background.js:
function highlightResults(results) {
console.log(133, results);
if (results.count > 0) {
browser.find.highlightResults();
}
}
function processMessage(message) {
console.log(10, message.selectedText);
console.log(11, browser.browsingContext);
switch (message.action) {
case "highlight":
if (message.selectedText) {
browser.find
.find(message.selectedText, {
caseSensitive: false,
includeRectData: false,
includeRangeData: false
})
.then(highlightResults)
.catch(e => console.error("!!", e));
}
break;
}
}
console.log(111);
browser.runtime.onMessage.addListener(processMessage);
Actual results:
Nothing happened. When I check in the console debugger, it shows these log (one line per log):
111 background.js:28:9
10 calls background.js:9:11
11 undefined background.js:10:11
133 Object { count: 4 } background.js:2:11
Error: no search results to highlight
Expected results:
When I select any text in the page, it should highlight them.
Reporter | ||
Comment 1•5 years ago
|
||
It seems that browser.find.highlightResults();
fails to highlight the latest browser.find.find()
result.
Hi iamtonylee,
Thanks for your report.
I followed the steps you mentioned in Comment #1, with a slight change: I saved the first "highlights.js" as "manifest.js", went to about:debugging and selected Load Temporary Add-on. Nothing happened as a result.
Could you please share any additional step I might have missed so I can try to reproduce this bug?
Thanks,
Virginia
Reporter | ||
Comment 3•5 years ago
|
||
Hi Virginia,
Thanks for your reply. Please check the latest plugin code here: https://bitbucket.org/hktonylee/highlight-all/src/master/
And the detailed steps are:
- check out the above project
- open Firefox
- open "about:debugging" > "This Firefox" > "Load Temporary Add-on..."
- open the manifest.json file in the project
- click "Inspect" button of this temporary add-on to open extension inspector
- you should see
Loading background.js 111
- open any tab, open any page, and double click any word
- you will see these log in extension inspector:
10 opens 11 undefined 133 Object { count: 1 } Error: no search results to highlight
- The last error should not happen. Firefox should highlight whatever selected.
Cheers,
Tony
Comment 4•5 years ago
|
||
Hi,
Seems to be a duplicate of bug 1610191 that I reported one month ago, and which is already confirmed.
Jerome
Reporter | ||
Comment 5•5 years ago
|
||
Hi Jerome,
It is good to hear from you 😃 What a coincidence that I was checking why the highlightall plugin does not work anymore LOL Your extension is really useful haha. Hope Firefox can solve this problem soon.
Tony
Reporter | ||
Updated•5 years ago
|
Assignee | ||
Comment 7•5 years ago
|
||
This is probably a different bug. I have a fix.
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Comment 8•5 years ago
|
||
This code didn't handle the missing optional rangeIndex parameter correctly.
Probably because all tests for highlightResults used a rangeIndex.
Assignee | ||
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Comment 10•5 years ago
|
||
Updated•5 years ago
|
Comment 11•5 years ago
|
||
bugherder |
Updated•5 years ago
|
Description
•