Closed Bug 1615761 Opened 9 months ago Closed 8 months ago

browser.find.highlightResults() does not work properly

Categories

(WebExtensions :: General, defect)

72 Branch
defect
Not set
normal

Tracking

(firefox-esr68 unaffected, firefox73 wontfix, firefox74 wontfix, firefox75 fixed)

RESOLVED FIXED
mozilla75
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:

  1. 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.

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

Component: Untriaged → General
Flags: needinfo?(iamtonylee)
Product: Firefox → WebExtensions

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:

  1. check out the above project
  2. open Firefox
  3. open "about:debugging" > "This Firefox" > "Load Temporary Add-on..."
  4. open the manifest.json file in the project
  5. click "Inspect" button of this temporary add-on to open extension inspector
  6. you should see
    Loading background.js
    111
    
  7. open any tab, open any page, and double click any word
  8. you will see these log in extension inspector:
    10 opens
    11 undefined
    133 
    Object { count: 1 }
    Error: no search results to highlight
    
  9. The last error should not happen. Firefox should highlight whatever selected.

Cheers,
Tony

Flags: needinfo?(iamtonylee)

Hi,

Seems to be a duplicate of bug 1610191 that I reported one month ago, and which is already confirmed.

Jerome

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

Status: UNCONFIRMED → RESOLVED
Closed: 8 months ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1610191

This is probably a different bug. I have a fix.

Assignee: nobody → evilpies
Status: RESOLVED → REOPENED
Ever confirmed: true
Resolution: DUPLICATE → ---

This code didn't handle the missing optional rangeIndex parameter correctly.
Probably because all tests for highlightResults used a rangeIndex.

Duplicate of this bug: 1610191
Pushed by evilpies@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/3f981ef78196
Fix browser.find.highlightResults without a rangeIndex parameter. r=mixedpuppy
Status: REOPENED → RESOLVED
Closed: 8 months ago8 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla75
You need to log in before you can comment on or make changes to this bug.