1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-19 19:52:51 +02:00
This commit is contained in:
gorhill 2017-02-18 09:01:36 -05:00
parent ea8cca1445
commit 39f9d11ec5

View File

@ -976,16 +976,23 @@ vAPI.net.registerListeners = function() {
// logger, etc. // logger, etc.
// Counterpart of following block of code is found in "vapi-client.js" -- // Counterpart of following block of code is found in "vapi-client.js" --
// search for "https://github.com/gorhill/uBlock/issues/1497". // 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) { 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'; details.type = 'websocket';
var requestURL = details.url;
var matches = /[?&]url=([^&]+)/.exec(requestURL);
details.url = decodeURIComponent(matches[1]); details.url = decodeURIComponent(matches[1]);
var r = onBeforeRequestClient(details); var r = onBeforeRequestClient(details);
// Blocked?
if ( r && r.cancel ) { return r; } if ( r && r.cancel ) { return r; }
// Try to redirect to the URL of an image already present in the // Redirect to the provided URL, or a 1x1 data: URI if none provided.
// document, or a 1x1 data: URL if none is present.
matches = /[?&]r=([^&]+)/.exec(requestURL); matches = /[?&]r=([^&]+)/.exec(requestURL);
return { return {
redirectUrl: matches !== null ? redirectUrl: matches !== null ?
@ -997,11 +1004,9 @@ vAPI.net.registerListeners = function() {
var onBeforeRequestClient = this.onBeforeRequest.callback; var onBeforeRequestClient = this.onBeforeRequest.callback;
var onBeforeRequest = function(details) { var onBeforeRequest = function(details) {
// https://github.com/gorhill/uBlock/issues/1497 // https://github.com/gorhill/uBlock/issues/1497
if ( if ( details.url.endsWith('ubofix=f41665f3028c7fd10eecf573336216d3') ) {
details.type === 'image' && var r = onBeforeWebsocketRequest(details);
details.url.endsWith('ubofix=f41665f3028c7fd10eecf573336216d3') if ( r !== undefined ) { return r; }
) {
return onBeforeWebsocketRequest(details);
} }
normalizeRequestDetails(details); normalizeRequestDetails(details);