Index: safari/ext/content.js |
diff --git a/safari/ext/content.js b/safari/ext/content.js |
index 25d64b006a20a69e14c8e2f9db5d4686ca8970d8..13992e1f5e4a46574aed4c4c967e9df25fd5fd04 100644 |
--- a/safari/ext/content.js |
+++ b/safari/ext/content.js |
@@ -25,23 +25,33 @@ |
/* Intialization */ |
- var beforeLoadEvent = document.createEvent("Event"); |
- beforeLoadEvent.initEvent("beforeload", false, true); |
+ var applicatonVersion = navigator.userAgent.match(/Version\/([\d.]+)/)[1]; |
+ var majorApplicationVersion = parseInt(applicatonVersion.split(".")[0], 10); |
- // Decide if we should use the new content blocker API or not. (Note when the |
- // API is used Safari breaks the canLoad function, making it either throw an |
- // exception or return true when used.) |
+ var beforeLoadEvent; |
var usingContentBlockerAPI = true; |
- try |
- { |
- if (safari.self.tab.canLoad(beforeLoadEvent, |
- {category: "request", |
- payload: {type: "prefs.get", |
- key: "safariContentBlocker"}}) != true) |
- usingContentBlockerAPI = false; |
- } |
- catch (e) |
+ |
+ // Safari 12 automatically disables extensions which use the old canLoad API, |
+ // so avoid using the old APIs on Safari 12! |
+ if (majorApplicationVersion < 12) |
{ |
+ beforeLoadEvent = document.createEvent("Event"); |
+ beforeLoadEvent.initEvent("beforeload", false, true); |
+ |
+ // Decide if we should use the new content blocker API or not. (Note when the |
+ // API is used Safari breaks the canLoad function, making it either throw an |
+ // exception or return true when used.) |
+ try |
Sebastian Noack
2018/07/13 18:27:53
It seems this kind of feature detection is obsolet
kzar
2018/07/13 18:58:33
I don't think this logic is redundant, it's how we
|
+ { |
+ if (safari.self.tab.canLoad(beforeLoadEvent, |
+ {category: "request", |
+ payload: {type: "prefs.get", |
+ key: "safariContentBlocker"}}) != true) |
+ usingContentBlockerAPI = false; |
+ } |
+ catch (e) |
+ { |
+ } |
} |
var isTopLevel; |
@@ -63,7 +73,8 @@ |
isTopLevel: isTopLevel, |
isPrerendered: isPrerendered, |
documentId: documentId, |
- legacyAPISupported: "canLoad" in safari.self.tab && |
+ legacyAPISupported: majorApplicationVersion < 12 && |
+ "canLoad" in safari.self.tab && |
"onbeforeload" in Element.prototype |
}); |
} |
@@ -183,14 +194,17 @@ |
}, |
sendMessageSync: function(message) |
{ |
- return safari.self.tab.canLoad( |
- beforeLoadEvent, |
- { |
- category: "request", |
- documentId: documentId, |
- payload: message |
- } |
- ); |
+ if (majorApplicationVersion < 12) |
+ { |
+ return safari.self.tab.canLoad( |
+ beforeLoadEvent, |
+ { |
+ category: "request", |
+ documentId: documentId, |
+ payload: message |
+ } |
+ ); |
+ } |
} |
}; |