From 39f9d11ec52fa0da5ae96b9f670c08b651d26925 Mon Sep 17 00:00:00 2001 From: gorhill Date: Sat, 18 Feb 2017 09:01:36 -0500 Subject: [PATCH] prepare uBO for fix to https://github.com/gorhill/uBO-Extra/issues/29 --- platform/chromium/vapi-background.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 63290d47b..2a4fdd66d 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -976,16 +976,23 @@ vAPI.net.registerListeners = function() { // logger, etc. // Counterpart of following block of code is found in "vapi-client.js" -- // search for "https://github.com/gorhill/uBlock/issues/1497". + // + // Once uBO 1.11.1 and uBO-Extra 2.12 are widespread, the image-based + // handling code can be removed. var onBeforeWebsocketRequest = function(details) { + if ( (details.type !== 'image') && + (details.method !== 'HEAD' || details.type !== 'xmlhttprequest') + ) { + return; + } + var requestURL = details.url, + matches = /[?&]u(?:rl)?=([^&]+)/.exec(requestURL); + if ( matches === null ) { return; } details.type = 'websocket'; - var requestURL = details.url; - var matches = /[?&]url=([^&]+)/.exec(requestURL); details.url = decodeURIComponent(matches[1]); var r = onBeforeRequestClient(details); - // Blocked? if ( r && r.cancel ) { return r; } - // Try to redirect to the URL of an image already present in the - // document, or a 1x1 data: URL if none is present. + // Redirect to the provided URL, or a 1x1 data: URI if none provided. matches = /[?&]r=([^&]+)/.exec(requestURL); return { redirectUrl: matches !== null ? @@ -997,11 +1004,9 @@ vAPI.net.registerListeners = function() { var onBeforeRequestClient = this.onBeforeRequest.callback; var onBeforeRequest = function(details) { // https://github.com/gorhill/uBlock/issues/1497 - if ( - details.type === 'image' && - details.url.endsWith('ubofix=f41665f3028c7fd10eecf573336216d3') - ) { - return onBeforeWebsocketRequest(details); + if ( details.url.endsWith('ubofix=f41665f3028c7fd10eecf573336216d3') ) { + var r = onBeforeWebsocketRequest(details); + if ( r !== undefined ) { return r; } } normalizeRequestDetails(details);