JavaScript functions are not defined at page load even though they have been declared

RESOLVED WORKSFORME

Status

()

Core
General
--
major
RESOLVED WORKSFORME
12 years ago
8 years ago

People

(Reporter: Andy, Unassigned)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(URL)

Attachments

(1 attachment)

(Reporter)

Description

12 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1) Gecko/20061010 Firefox/2.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1) Gecko/20061010 Firefox/2.0

This is an intermittent problem that only appears at certain times. The system complains about JavaScript functions not being defined but this is false as the functions have been declared earlier. Seems to be a timing issue on page load

Reproducible: Sometimes

Steps to Reproduce:
1. Visit above page and press F5 to refresh whilst moving the mouse over the link
2.
3.

Comment 1

12 years ago
Confirmed, moving the mouse over and out on the link while pressing F5 consistently triggered an error for me.

This doesn't make much sense, the script inside the onmouseover HTML event handler shouldn't be able to run before the script itself has been rendered. Perhaps this happens while the page is unloading, with the script functions being removed before the bound event handlers?

Comment 2

12 years ago
WFM, Mac trunk.
Component: Error Console → General
QA Contact: javascript.console → general

Comment 3

12 years ago
This is confirmed.  I have noticed on several sites.
(Reporter)

Comment 4

12 years ago
I have added some random text to increase the download time of the page. This helps to demonstrate the problem.

It appears as though the function is not available until the end of the document. This shows up regularly on bigger pages. The more content the page contains the worse the problem becomes.

Hope this helps,
Andy
Severity: normal → major
Version: unspecified → 2.0 Branch

Comment 5

12 years ago
We think this is the same bug as reported for the Prototype.js framework:

http://dev.rubyonrails.org/ticket/5393

Comment 6

11 years ago
I've confirmed this bug first occurring in Firefox version 1.5.0.1rc1. However, this is obviously more related to the core changes at the time (which seem to be related to 1.8.1). I haven't been able to find an immediately-suspicious ticket.

If there's any topic that this relates to, in particular, it's the execution of DOM events (either they're occurring too early, or their global context isn't being set properly). Although, I don't see any tickets that deal with that specific issue (for that particular release), so some hunting will still have to occur.
Component: General → General
Product: Firefox → Core
QA Contact: general → general
Version: 2.0 Branch → Trunk

Comment 7

11 years ago
Created attachment 294656 [details]
Test showing event handlers called with missing window scope

Attaching a revised version of the original test that uses mousemove events instead of mouse over, which makes reproducing the problem easier. (I usually 2-3 "customFunction is not defined" errors.)

This test demonstrates that event handlers are getting triggered without the scope-chain properly configured.  In this case, the 'window' object does not appear to be in the scope chain, which is why "customFunction()" causes a ReferenceError, but "window.customFunction()" doesn't.
DUP of Bug 252542 (Reload case)? Test case is very similar to this bug's one.
See also Bug 199430 (load of new URL by FORM case).

Comment 9

8 years ago
The testcase works for me, and these symptoms were fixed, as bugs cited in comment 8 say. Resolving.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 8 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.