Closed Bug 300065 Opened 19 years ago Closed 19 years ago

event.originalTarget sometimes fails

Categories

(Core :: DOM: Events, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: mcm.ham, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b3) Gecko/20050707 Firefox/1.0+
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b3) Gecko/20050707 Firefox/1.0+

http://kb.mozillazine.org/Dev_:_Extensions_:_Example_Code_:_On_Tab_Load

I have been using the code from that site to trigger a page onload event.
However, I have found that sometimes this does not work. Through the use of
alert boxes I have found that it fails on this line:

var doc = aEvent.originalTarget;

I get this to fail sometimes on Mozilla 1.8 and on the trunk builds but have
never been able to reproduce the problem on Firefox 1.0.x or Mozilla 1.7.

Reproducible: Sometimes

Steps to Reproduce:
1. Install Adblock Plus from http://bene.sitesled.com/install.htm
2. Create this filter /(dynamic|text)ad/
3. Visit http://www.windowsitpro.com/windowspaulthurrott/

Actual Results:  
The online monthly pass ad and the tech jobs at dice ad in the articles are
removed only sometimes. And when it fails clicking on the Adblock text at the
bottom of the browser to bring up Adblock-able items does not show any DIV nodes
like it does when it works.

Expected Results:  
This should consistently work and not sometimes.

Where this is coded in Adblock Plus is in the adblock.xul file which should call
the removeUnwantedDivs function near the top of the component.js file.
I have it set to remove ads, and when i view that page after temp. allowing in
NoScript, the ads oad, then they dissapear when it is finished loading
This has nothing to do with the sites javascript so you can leave Noscript
enabled. If the ads load and then disappear then that means it is working since
it's an onload page event. I find I have to play around reloading and go into
the articles a couple of times before it fails. This is an intermittent bug
where sometimes it fails regularly and other times hardly at all :(
Thanks for responding Shayne, I wasn't meaning to sound so Brash with my first
sentence, sorry.

I've just discovered XPaths, instead of the old method of looping through the
DIVs. Here's an extract:

function removeUnwantedDivs(e, node)
{
  if ( typeof(node)=='undefined' ) node = e.originalTarget;
  var result = node.evaluate("//div", node, null,
      XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  ...
}

Using this method I finally get an error message to the Javascript console when
it fails:

  Error: node.evaluate is not a function

So will see what I can find out.
From my experience somewhere between Firefox 1.5 beta 1 and Firefox 1.5 beta 2
this bug seems to have been fixed.
duplicate of bug 305640
sry for bug spam:

previous comment was a question
It is very likely a dupe of another bug. However, this issue was around long before that particular bug you linked regressed. But thanks for pointing it out.
Michael, is this still an issue in current builds?
Nope, I think this is fixed now including the trunk. I was leaving it open to do some more testing since it happens only intermittently but it hasn't failed for me yet. And going back to older builds I can reproduce still.

It also seems another bug I was experiencing with Fx 1.0.x and above where retrieving the node from the onload page event was sometimes other random html related nodes instead of HTMLDocument is now also fixed.
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.