From d2cc20ed470817f2bbdc380990bae9217f4fd9f7 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 12 Feb 2015 16:29:58 -0700 Subject: [PATCH] Safari: important improvements to request capturing + fix twitch.tv twitch.tv now works out of the box in HTML5 in Safari. Make sure you disable Flash if you don't get the HTML5 player. --- assets/checksums.txt | 2 +- assets/ublock/filters.txt | 3 +++ platform/safari/vapi-client.js | 16 +++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/assets/checksums.txt b/assets/checksums.txt index b16bd16c3..557735cbb 100644 --- a/assets/checksums.txt +++ b/assets/checksums.txt @@ -1,5 +1,5 @@ 7edb2a585b445f28aa5ab06306f1a23f assets/ublock/privacy.txt -2818b73e0bcbea13800c9c006b2d521d assets/ublock/filters.txt +f8ef909c16003b6ef79a502998c83dee assets/ublock/filters.txt dcf3e05bae803343c9d632f0baf8bedd assets/ublock/mirror-candidates.txt 48f4e02826d244a48d140cb5e4b81114 assets/ublock/filter-lists.json 132b3ecc9da8a68c3faf740c00af734b assets/thirdparties/adblock-plus-japanese-filter.googlecode.com/hg/abp_jp.txt diff --git a/assets/ublock/filters.txt b/assets/ublock/filters.txt index cd802148b..c2a3b4e37 100644 --- a/assets/ublock/filters.txt +++ b/assets/ublock/filters.txt @@ -292,3 +292,6 @@ deviantart.com##.dp-ad-chrome.dp-ad-visible # https://github.com/gorhill/uBlock/issues/774 # To counter `carbonads.net` in Peter Lowe's @@||carbonads.net^$~third-party + +# This enables twitch.tv to work in HTML5 +@@||imasdk.googleapis.com$domain=twitch.tv diff --git a/platform/safari/vapi-client.js b/platform/safari/vapi-client.js index e12b5a821..2e6285f5f 100644 --- a/platform/safari/vapi-client.js +++ b/platform/safari/vapi-client.js @@ -29,6 +29,7 @@ } vAPI.vapiClientInjected = true; vAPI.safari = true; + /******************************************************************************/ var messagingConnector = function(response) { if(!response) { @@ -74,6 +75,9 @@ requestId: 1, connectorId: uniqueId(), setup: function() { + if(typeof safari === "undefined") { + return; + } this.connector = function(msg) { // messages from the background script are sent to every frame, // so we need to check the connectorId to accept only @@ -107,6 +111,9 @@ channelName: channelName, listener: typeof callback === 'function' ? callback : null, send: function(message, callback) { + if(typeof safari === "undefined") { + return; + } if(!vAPI.messaging.connector) { vAPI.messaging.setup(); } @@ -157,8 +164,7 @@ // Helper event to message background, // and helper anchor element var beforeLoadEvent = new Event("beforeload"), - linkHelper = document.createElement("a"), - isHttp_s = /^https?:/; + linkHelper = document.createElement("a"); // Inform that we've navigated if(frameId === 0) { @@ -186,10 +192,10 @@ return !(safari.self.tab.canLoad(beforeLoadEvent, details)); }; var onBeforeLoad = function(e) { - if(e.url.charCodeAt(0) !== 104 && !isHttp_s.test(e.url)) { // h = 104 + linkHelper.href = e.url; + if(linkHelper.protocol.charCodeAt(0) !== 104) { // h = 104 return; } - linkHelper.href = e.url; var details = { url: linkHelper.href, type: nodeTypes[e.target.nodeName.toLowerCase()] || "other", @@ -199,7 +205,7 @@ timeStamp: Date.now() }; var response = safari.self.tab.canLoad(e, details); - if(!response) { + if(response === false) { e.preventDefault(); } };