Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

finding event "at end of page load", redux

2 views
Skip to first unread message

Ray Kiddy

unread,
Apr 21, 2008, 6:14:36 PM4/21/08
to

I have an extension which I use in automated testing which waits for a
page to load and then shuts down the Firefox instance. This may seem
harsh, but if you want to start Firefox instances and then shut the
instance down without human intervention, this is what I think one has
to do. Testing page loading in a single running instance seems wrong.
The loading time of a page would, I think, be affected by the behavior
of earlier pages.

But the question of what event one could look for that would represent
the end of the page loading is a complicated one. Right now, my
extension looks for the first DOMContentLoaded that occurs after an
onload. DOMContentLoaded occurs more than once, so you have to wait for it.

I was asked about this recently and I thought of something that might be
more meaningful, but may be more hassle than it is worth.

What occurred to me is that I could look for the CSS RestyleEvent. But,
I think I would have to look for any tag that took a src attribute (img,
frame, iframe, input, script) and wait for all RestyleEvent occurrences
from any of these as well. And, actually, I would have to make sure more
tags were not added, and then wait for those if there were new tags. But
this is getting a little complicated.

Is there any value in this approach at all? Does anyone have anything
simpler that really is a "this page has loaded" event?

cheers - ray

Boris Zbarsky

unread,
Apr 21, 2008, 10:14:54 PM4/21/08
to
Ray Kiddy wrote:
> But the question of what event one could look for that would represent
> the end of the page loading is a complicated one. Right now, my
> extension looks for the first DOMContentLoaded that occurs after an
> onload.

What's wrong with using onload or onpageshow? You're trying to catch cases
where the page's onload handler makes some changes to the DOM?

If so, how do you define "loaded" for http://news.bbc.co.uk or some other page
that has a JS ticker?

-Boris

Ray Kiddy

unread,
Apr 22, 2008, 8:07:36 PM4/22/08
to
Boris Zbarsky wrote:
> Ray Kiddy wrote:
>> But the question of what event one could look for that would represent
>> the end of the page loading is a complicated one. Right now, my
>> extension looks for the first DOMContentLoaded that occurs after an
>> onload.
>
> What's wrong with using onload or onpageshow? You're trying to catch
> cases where the page's onload handler makes some changes to the DOM?
>

There seems to be lots of things that happen after onload. For example,
others have observed and mentioned to me that they want to wait until
images load. Apparently, this may happen after the onload event.

I have not tried onpageshow.

> If so, how do you define "loaded" for http://news.bbc.co.uk or some
> other page that has a JS ticker?
>
> -Boris

Actually, that is why I put "at end of page load" in quotes. I think
this phrase means what the speaker wants it to mean. I have, at other
times, discussed events and have also said that the use of Ajax stuff
makes this phrase mean less and less.

That being said, it would be good to know what events actually represent.

For example, there are many stages in the process of page loading. I
recall that Dave Hyatt (the guy who works at Apple) had written about
the stages, as he sees them, when writing about performance issues. I
wish I could find that post.

Do we have a document that describes the stages of page loading and what
events are fired before and after each. There seem to be more than a few
bugs asking for the meaning of events. There also seem to be multiple
newsgroup posts about this. Just from a quick scan of bugzilla, I see:

Bug 286013 – DOM dispatches undocumented events and expects embedders
handle them
toBug 329514 – Sort out the exact behavior for *LOAD events


Boris - You have commented on one of these and created the other. Doing
a search on 'load event' turns up lots of others.

- ray


Boris Zbarsky

unread,
Apr 22, 2008, 10:04:15 PM4/22/08
to
Ray Kiddy wrote:
> There seems to be lots of things that happen after onload. For example,
> others have observed and mentioned to me that they want to wait until
> images load. Apparently, this may happen after the onload event.

On trunk, only if the images _start_ to load after the onload event. On branch,
onload didn't wait for backgrounds, so that might be what people are talking about.

> I have not tried onpageshow.

It fires at the same time as onload, except for history navigation cases.

> Actually, that is why I put "at end of page load" in quotes. I think
> this phrase means what the speaker wants it to mean.

Right. I just think it's important to have a clear decision criterion for what
it means to be "at end of page load" before even bothering to ask the "how do I
detect it?" question.

> That being said, it would be good to know what events actually represent.

onload represents the completion of all network activity associated with the
page that began prior to the firing of the onload event. That is, it represents
the first time after the page started to load that there are no network
connections associated with the page that are still in progress.

> Do we have a document that describes the stages of page loading and what
> events are fired before and after each.

I don't know that we do. Sounds like possible devmo material. That said, the
only events like this that we have are DOMContentLoaded, onload, and onpageshow.
DOMContentLoaded is certainly well-documented (including in the HTML5 drafts).
There is certainly documentation about how onload and onpageshow differ.

> Bug 286013 – DOM dispatches undocumented events and expects embedders
> handle them

Yes, I'm well aware of that bug, as you noticed.

> toBug 329514 – Sort out the exact behavior for *LOAD events

Those are all reflected into the DOM as onload events on different targets.

> Boris - You have commented on one of these and created the other. Doing
> a search on 'load event' turns up lots of others.

Yes, but are they questions about what events mean what, or just questions about
when the Window's onload event should fire?

-Boris

Ray Kiddy

unread,
Apr 23, 2008, 1:10:45 PM4/23/08
to
Boris Zbarsky wrote:
> Ray Kiddy wrote:
>> There seems to be lots of things that happen after onload. For
>> example, others have observed and mentioned to me that they want to
>> wait until images load. Apparently, this may happen after the onload
>> event.
>
> On trunk, only if the images _start_ to load after the onload event. On
> branch, onload didn't wait for backgrounds, so that might be what people
> are talking about.

That makes sense.

>> I have not tried onpageshow.
>
> It fires at the same time as onload, except for history navigation cases.

Good to know.

>> Actually, that is why I put "at end of page load" in quotes. I think
>> this phrase means what the speaker wants it to mean.
>
> Right. I just think it's important to have a clear decision criterion
> for what it means to be "at end of page load" before even bothering to
> ask the "how do I detect it?" question.

I agree, except that people _will_ use the phrase "at the end of the
page load" regardless of what anyone else thinks they should do so.
Perhaps the devmo article you describe below needs to inform them on this.

>> That being said, it would be good to know what events actually represent.
>
> onload represents the completion of all network activity associated with
> the page that began prior to the firing of the onload event. That is,
> it represents the first time after the page started to load that there
> are no network connections associated with the page that are still in
> progress.

This paragraph, and your note about onpageshow above, are exactly the
kind of thing the devmo article needs to mention. If you do not write
it, I will create the page and steal this info for the page.

>> Do we have a document that describes the stages of page loading and
>> what events are fired before and after each.
>
> I don't know that we do. Sounds like possible devmo material. That
> said, the only events like this that we have are DOMContentLoaded,
> onload, and onpageshow. DOMContentLoaded is certainly well-documented
> (including in the HTML5 drafts). There is certainly documentation about
> how onload and onpageshow differ.
>
>> Bug 286013 – DOM dispatches undocumented events and expects embedders
>> handle them
>
> Yes, I'm well aware of that bug, as you noticed.
>
>> toBug 329514 – Sort out the exact behavior for *LOAD events
>
> Those are all reflected into the DOM as onload events on different targets.
>
>> Boris - You have commented on one of these and created the other.
>> Doing a search on 'load event' turns up lots of others.
>
> Yes, but are they questions about what events mean what, or just
> questions about when the Window's onload event should fire?

I think they probably _are_ questions about what the events mean.
Unfortunately, I do not think that enables us to duck the questions. The
more people understand what an event is supposed to mean, the better
they will be able to judge whether they should use it and how to not
mis-use it.

cheers - ray

Boris Zbarsky

unread,
Apr 23, 2008, 1:35:47 PM4/23/08
to
Ray Kiddy wrote:
> This paragraph, and your note about onpageshow above, are exactly the
> kind of thing the devmo article needs to mention. If you do not write
> it, I will create the page and steal this info for the page.

Please feel free. I'm not likely to do any article-writing until June, at least.

-Boris

0 new messages