diff --git a/ext/bg.js b/ext/bg.js index 190ed1f..95b1971 100644 --- a/ext/bg.js +++ b/ext/bg.js @@ -459,6 +459,26 @@ function attach_ws_events(ws){ if(status){ + if( + msg.proxy.type == "http" || + msg.proxy.type == "https" + ){ + + if(typeof msg.proxy.proxyDNS == "boolean"){ + + delete msg.proxy.proxyDNS; + } + + + } + + if(typeof msg.proxy.port == "string"){ + + msg.proxy.port = parseInt(msg.proxy.port); + } + + console.log(msg.proxy); + proxy_map[msg.id] = msg.proxy; send(ws, seqid, {status: true}); return; @@ -731,6 +751,44 @@ browser.proxy.onRequest.addListener(function(request){ urls: [""] }); +// Automatically handle and detect all Proxy Authentication challenges +browser.webRequest.onAuthRequired.addListener( + function(details){ + + // Only intercept proxy auth requests, ignore normal website auth + if(!details.isProxy){ + return {}; + } + + const proxy_config = proxy_map[details.cookieStoreId]; + + // Check if the assigned proxy configuration for this container includes credentials + if( + proxy_config && + ( + proxy_config.type == "http" || + proxy_config.type == "https" + ) && + proxy_config.username && + proxy_config.password + ){ + + return { + authCredentials: { + username: proxy_config.username, + password: proxy_config.password + } + }; + } + + // If the proxy requires auth and we have no credentials, silently cancel + // to prevent hanging the browser with auth popup dialogs. + return { cancel: true }; + }, + { urls: [""] }, + ["blocking"] +); + browser.tabs.onUpdated.addListener(function(tabid, event, tab){ if(global_ws === null){ return; } @@ -768,6 +826,21 @@ browser.webRequest.onHeadersReceived.addListener( // send error on 4xx code if(page.statusCode >= 400){ + const proxy_config = proxy_map[details.cookieStoreId]; + + if( + proxy_config && + ( + proxy_config.type == "http" || + proxy_config.type == "https" + ) && + page.statusCode === 407 + ){ + + // ignore http proxy auth error + return; + } + send_event( global_ws, {