Index: safari/ext/content.js |
=================================================================== |
--- a/safari/ext/content.js |
+++ b/safari/ext/content.js |
@@ -66,12 +66,15 @@ |
if (!/^https?:/.test(url)) |
return; |
- var type; |
+ var type = "other"; |
+ var eventName = "error"; |
+ |
switch(event.target.localName) |
{ |
case "frame": |
case "iframe": |
type = "sub_frame"; |
+ eventName = "load"; |
break; |
case "img": |
type = "image"; |
@@ -85,12 +88,8 @@ |
break; |
case "link": |
if (/\bstylesheet\b/i.test(event.target.rel)) |
- { |
type = "stylesheet"; |
- break; |
- } |
- default: |
- type = "other"; |
+ break; |
} |
if (!safari.self.tab.canLoad( |
@@ -105,15 +104,18 @@ |
{ |
event.preventDefault(); |
- // Safari doesn't dispatch an "error" event when preventing an element |
- // from loading by cancelling the "beforeload" event. So we have to |
- // dispatch it manually. Otherwise element collapsing wouldn't work. |
- if (type != "sub_frame") |
+ // Safari doesn't dispatch all the expected events for elements that |
+ // have been prevented from loading by having their "beforeload" event |
+ // cancelled. "error" events are never dispatched, and since Safari 8 |
+ // "load" events are also not dispatched, when blocking frames. |
+ // We need to dispatch those events manually here to avoid breaking |
+ // element collapsing and pages that rely on those events. |
+ if (type != "sub_frame" || parseInt(navigator.userAgent.match(/\bVersion\/(\d+)/)[1], 10) >= 8) |
{ |
setTimeout(function() |
{ |
var evt = document.createEvent("Event"); |
- evt.initEvent("error"); |
+ evt.initEvent(eventName); |
event.target.dispatchEvent(evt); |
}, 0); |
} |