Open Bug 488427 Opened 15 years ago Updated 1 year ago

nsIFind needs to call FlushPendingNotifications


(Core :: DOM: Core & HTML, defect)

Windows Vista




(Reporter: Honza, Unassigned)


(Keywords: good-first-bug, helpwanted, student-project)


(3 files)

When nsIFind is used to search also within dynamically inserted content, the Find method always returns null (even if the searched text is there). 

Here is a scenario that describes the problem.

#1) The page, displays a list of expandable items. If an item is
expanded, its body is dynamically inserted into the page (just another
piece of HTML).

#2) The search should include current HTML on the page and also all
bodies that don't have to exist on the page (typically all items are

#3) If the search algorithm, finds out that the specified text is
within a body that is *not* currently displayed, the body (HTML) is
dynamically inserted (visually, the item is automatically expanded).

#4) The new created DOM is immediately used to create a DOM range and
passed to range-finder (nsIFind). But it always returns null even if
the text is there (I can see it on the page)...

If the step #4 is executed asynchronously, it works and the finder
returns proper range (nsIDOMRange). 

The possible workaround is to read "document.body.offsetWidth;" on the document in question between inserting the new DOM nodes and making the nsIFind call

According to the preceding discussion here:

...this means that nsIFind just needs to call FlushPendingNotifications in
the appropriate methods.
Summary: nsIFind needs to call Flush PendingNotifications → nsIFind needs to call FlushPendingNotifications
Version: unspecified → Trunk
Flags: blocking1.9.2?
Whiteboard: [good first bug]
I'd love to see this for 1.9.2, but I don't think I'd hold the release for it.
Flags: wanted1.9.2+
Flags: blocking1.9.2?
Flags: blocking1.9.2-
Attached file Testcase
I'm having trouble reproducing this bug.  I've attached a mochitest testcase which works for me.  Could you have a look and let me know if this is different from what you're doing?
Assignee: nobody → jlebar
Attached patch patch and testSplinter Review
I can't seem to reproduce the bug,  This test passes both with and without the patch. Can you check if this patch helps?
Today is code freeze for 1.9.2, so I'm going to go ahead and mark this one as worksforme. If anyone can come up with a failing testcase or suggest how to change mine or David's so they fail, we can re-open this bug.
Closed: 15 years ago
Resolution: --- → WORKSFORME
This bug still bites me in Firefox 7.0.1. My extension, Googlebar Lite, uses the nsIFind interface to perform search term highlighting. If I don't use the workaround listed in the original poster's text, the nsIFind interface will skip to the end of the current DOM element, and go on to the next sibling element.

For example, assume that I have two paragraphs on a page, both of which have the word "Firefox" listed several times in each. Without the workaround, here's what happens:

1. The interface finds the first result in paragraph 1.
2. I surround said result with a styled span element.
3. I continue searching by calling nsIFind::Find() again. The second time around the loop, it has apparently skipped to paragraph 2 because the DOM has changed beneath its feet.

If I can find some time, I'll try to cook up a new test case. With my extension, I was able to consistently reproduce this before finding this workaround.
This new test case illustrates the reported problem with nsIFind in Firefox. It takes a different approach from the previous test case, but illustrates what I believe is the same problem.
Attachment #565545 - Attachment mime type: text/plain → text/html
I cannot seem to get the test case to work in browser now that it's posted here on Bugzilla, but it worked for me when saved as a local file on my system (using Firefox 7.0.1 on Windows XP). This is the first time I've posted a test case, so I may be missing something obvious. When I attempt to run it here on Bugzilla, I get the following error in my console:

Error: A script from "" was denied UniversalXPConnect privileges.
Source file:
Line: 9

Long story short, if it doesn't work for you, save it locally and try it.
Yeah, untrusted sites can't prompt for expanded privileges.
Resolution: WORKSFORME → ---
Component: DOM: Traversal-Range → DOM: Core & HTML
I encountered the same behaviour in FF22, developing an extension similar to Jonah Bishop. The workaround also solved the problem for me. Tried to reproduce it today in FF23 but couldn't, so either I've screwed up or something must have changed.
Keywords: good-first-bug
Whiteboard: [good first bug]

This good-first-bug hasn't had any activity for 6 months, it is automatically unassigned.
For more information, please visit auto_nag documentation.

Assignee: justin.lebar+bug → nobody
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.