[Webkit-unassigned] [Bug 15505] New: onload sometimes fired before all resources are loaded

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sun Oct 14 07:29:20 PDT 2007


http://bugs.webkit.org/show_bug.cgi?id=15505

           Summary: onload sometimes fired before all resources are loaded
           Product: WebKit
           Version: 522+ (nightly)
          Platform: Macintosh Intel
               URL: http://openlayers.org/dev/examples/
        OS/Version: Mac OS X 10.4
            Status: UNCONFIRMED
          Severity: Normal
          Priority: P2
         Component: New Bugs
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: crschmidt at crschmidt.net


Version 522.12.1, Safari 3.0.3

The above URL is a collection of examples of the OpenLayers Javascript library.
In the development version of OpenLayers, Javascript source files are loaded by
the following mechanism:

        var allScriptTags = "";
        var host = OpenLayers._getScriptLocation() + "lib/";

        for (var i = 0; i < jsfiles.length; i++) {
            if (/MSIE/.test(navigator.userAgent) ||
/Safari/.test(navigator.userAgent)) {
                var currentScriptTag = "<script src='" + host + jsfiles[i] +
"'></script>";
                allScriptTags += currentScriptTag;
            } else {
                var s = document.createElement("script");
                s.src = host + jsfiles[i];
                var h = document.getElementsByTagName("head").length ?
                           document.getElementsByTagName("head")[0] :
                           document.body;
                h.appendChild(s);
            }
        }
        if (allScriptTags) document.write(allScriptTags);

Occasionally, when loading an example in Safari, the page will fail to load,
reporting an error:

Value undefined (result of expression OpenLayers.Map) is not an object. Cannot
be used with new.
http://openlayers.org/dev/examples/example.html

This error generally indicates that the Javascript file containing the
definition for OpenLayers.Map is not yet available.

I've been able to get this to happen most regularly with the example.html
example: http://openlayers.org/dev/examples/example.html

The first javascript call is from a file which is loaded first: var header =
OpenLayers.Util.getElement("browserHeader");

But the OpenLayers.Map class, which is loaded later, is not available.

All actions are taking place on 'onload' (not before). 

The only explanation I can think of for this is that onload is firing before
all the included script resources -- which are written into the document via
document.write() -- are available. 

After causing the error to happen, refreshing the page seems to cause it to
always work. 

This may be merely anecdotal, but it seems to happen more often if I manually
enter the URL into the URL entry form, rather than following a link.

I was not able to reproduce this bug when running against a locally checked out
copy of OpenLayers (file:// URLs).

I believe the Safari-specific hack in the above loading code was added in
Safari2, and to the best of my knowledge, it worked relatively reliably there,
because appending elements to the DOM suffered the same problems as we are
seeing now. I have not confirmed whether switching to the non-Safari specific
method fixes this problem in Safari3.

This bug is not easily reproducible, insofar as it happens sometimes, but doing
the exact same thing, won't happen other times. It seems to happen most of tne
the first time I view a page (with the OpenLayers Library in it.)


-- 
Configure bugmail: http://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list