Bug 52577 - Incomplete beforeload event support
Summary: Incomplete beforeload event support
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Page Loading (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac (Intel) OS X 10.6
: P2 Normal
Assignee: Nobody
URL: http://www.nearinfinity.com/blogs/jef...
Keywords:
Depends on: 56424
Blocks:
  Show dependency treegraph
 
Reported: 2011-01-17 07:49 PST by Jeff
Modified: 2015-02-04 09:06 PST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff 2011-01-17 07:49:00 PST
The beforeload event in Webkit is extremely useful for things like blocking images or JavaScript from loading, but it's implementation is incomplete. For example, there is no beforeload event fired for link tags with rel=icon, rel=prefetch, or rel=dns-prefetch, no beforeload event for XMLHttpRequest calls, no beforeload event for any images loaded from stylesheet references, and no beforeload event prior to the default favicon being requested.

Please see the provided URL for a short discussion on the issues this presented while attempting to build a Safari extension similar to the HTTPS Everywhere Firefox extension developed by the EFF. Ideally, it would be great to have a beforeload event fired for any network request, regardless of the resource type being requested.
Comment 1 Gavin Peters 2011-03-15 16:37:23 PDT
Bug 56424 captures the icon and prefetch implications of this.
Comment 2 Michael Gundlach 2011-08-01 13:15:15 PDT
To append to Jeff's list: you can't block in-Flash resources using beforeload, which makes AdBlock For Safari incomplete.
Comment 3 Chris Aljoudi 2015-02-04 09:04:58 PST
Any updates on plans for fixing this?

This is incredibly crucial to how effective some popular extensions for Safari can be. 

`beforeload` should capture requests made by:

1) JavaScript XHR
2) JavaScript element creation (`new Image().src = "http://something.com/"`);
3) Resources for plugins running in a page
... that kind of thing

I'd be glad to spend time studying WebKit's source and adding support for this — please let me know if/whether/how I can help.
Comment 4 Chris Aljoudi 2015-02-04 09:06:13 PST
Right now, extensions such as µBlock are forced to use a hack where a script is injected into webpages which overrides the global `XMLHttpRequest` prototype. This is really bad, but it's the only way to get around this limitation.