Open Bug 715695 Opened 13 years ago Updated 2 years ago

add support for the 'beforeload' event

Categories

(Core :: DOM: Events, defect, P5)

defect

Tracking

()

People

(Reporter: blizzard, Unassigned)

Details

Attachments

(1 file)

The 'beforeload' event is a WebKit-specific event that's fired before resources are loaded from a page. This was originally added for the purposes of ad-blocking, but it's being used in clever ways on the web now. We've seen specific requests to support it. Test case attached.
This is all unspecified. It is not at all clear when the event should fire. Should style="background-image: foo.jpg" fire beforeload? Or is this only for things which fire load?
I don't know, some testing would be required. I do know that people are using the event.preventDefault() to keep resources from loading, though.
It's not being used in this case for content policy, it's just being used to prevent loading of some kinds of resources like images and scripts.
well, isn't contentpolicy exactly like that. prevent loading of some resources. Actually, didn't Benjamin have some ideas to use events for contentpolicy in E10s.
Spec please.
It was a very generic idea, we never got down to details. But yeah, we'd need to find/develop a spec to realistically consider this.
So I'd like to make a proposal here because we can kill two birds with one stone: 1. It would be nice to support something like this - a page can intercept & block load requests. That's basically what'beforeload' is used for. It needs a spec, yes. 2. One thing that's been requested forever is something that lets you know when resources have been loaded. I'd suggest that we do something like an 'afterload' event to match. The main use case here is for fonts - people who want to use custom fonts for drawing in the canvas element need to know when a font has loaded. This seems like a good way to know that, since it happens as a side effect of actually using it and fonts don't have an explicit load API like images do.
To put down the use cases I'm suggesting: 1. That we have the ability for user-page scripts to intercept and prevent in-page resources from loading. 2. That we have the ability to know when page resources are finished loading - even for implicit resources like background images and fonts.
#2 is covered by other bugs already. We should think long and hard before doing #1: it imposes some serious implementation constraints on the web platform. For example, it either makes speculative parsing/loading impossible or makes the beforeload events very limited in terms of the information they can have in them (or both at once).
'beforeload' and 'afterload' proposed for consideration to WHATWG: http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-January/034311.html
I'd really appreciate people not making claims like "Mozilla is strongly considering implementing X" unless it's actually true (as in, we have had some sort of discussion in our community, and buy-in). Usually those of us who post to various standards lists are _very_ careful to point out that we cannot speak for Mozilla in general pending such discussion...
OS: Windows 7 → All
Hardware: x86_64 → All
And the most trivial test possible shows that WebKit will happily start loads before firing "beforeload"; the only thing this event can reliably prevent is processing of the response. So the basic premise of comment 0 seems to be wrong. See testcase in http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-January/034320.html
OK, sorry. But the resource loading question is still there, even in the face of what to do with the speculative parser. It's an interesting an important capability.
Which resource loading question? And do you mean loading or processing? Also, did you read the whatwg thread in question or are we going to rehash parts of it here? ;)
the best case I come up with this event is quite similar to "beforescriptexecute" event for userscript, I use it to hijack page script, or just a time stamp to stop the parsing of the page a bit, adding something (mostly userstyle) in front of the BODY , so it won't "flash"
That last usecase, for an extension, is already covered by the "window created" notifications...
As of today, Blink removed support for beforeload event with roll out in Chromium Version 35.0.1913.0 (259825). Bug: https://code.google.com/p/chromium/issues/detail?id=333318 CL Review: https://codereview.chromium.org/205523003
Priority: -- → P5
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: