Open
Bug 715695
Opened 13 years ago
Updated 2 years ago
add support for the 'beforeload' event
Categories
(Core :: DOM: Events, defect, P5)
Core
DOM: Events
Tracking
()
NEW
People
(Reporter: blizzard, Unassigned)
Details
Attachments
(1 file)
419 bytes,
text/html
|
Details |
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.
Comment 1•13 years ago
|
||
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?
Reporter | ||
Comment 2•13 years ago
|
||
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.
Comment 3•13 years ago
|
||
beforeload is very much poor man's contentpolicy, not covering all the cases.
http://codesearch.google.com/codesearch#search/&exact_package=chromium&q=dispatchBeforeloadEvent%20file:WebCore&sq=&type=cs
Reporter | ||
Comment 4•13 years ago
|
||
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.
Comment 5•13 years ago
|
||
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.
Comment 6•13 years ago
|
||
Spec please.
Comment 7•13 years ago
|
||
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.
Reporter | ||
Comment 8•13 years ago
|
||
There doesn't appear to be anything like a spec. I've found a lot of mentions of it, though. It was built for extensions and is being used on the web now. Some examples:
https://webmynd.com/blog/2011/04/04/equivalent-to-beforeload-event-for-firefox-extensions/
http://stackoverflow.com/questions/5330048/event-before-load-event-for-firefox-extension
http://stackoverflow.com/questions/4395525/safari-extension-beforeload-event-documentation
Reporter | ||
Comment 9•13 years ago
|
||
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.
Reporter | ||
Comment 10•13 years ago
|
||
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.
![]() |
||
Comment 11•13 years ago
|
||
#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).
Comment 12•13 years ago
|
||
'beforeload' and 'afterload' proposed for consideration to WHATWG:
http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-January/034311.html
![]() |
||
Comment 13•13 years ago
|
||
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...
Updated•13 years ago
|
OS: Windows 7 → All
Hardware: x86_64 → All
![]() |
||
Comment 14•13 years ago
|
||
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
Reporter | ||
Comment 15•13 years ago
|
||
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.
![]() |
||
Comment 16•13 years ago
|
||
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? ;)
Comment 17•13 years ago
|
||
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"
![]() |
||
Comment 18•13 years ago
|
||
That last usecase, for an extension, is already covered by the "window created" notifications...
Comment 19•11 years ago
|
||
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
Updated•7 years ago
|
Priority: -- → P5
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•