diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc342ce --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +################################################################################ +# This .gitignore file was automatically created by Microsoft(R) Visual Studio. +################################################################################ + +/.vs/Extention/FileContentIndex/10121bdc-6315-4f6e-94ac-fd1a46abeb7f.vsidx +/.vs/Extention/FileContentIndex/10c93d41-d82c-482f-a617-105e967bc9de.vsidx +/.vs/Extention/FileContentIndex/55fe423a-ecf3-4840-ab4e-afdab2848472.vsidx +/.vs/Extention/FileContentIndex/723f158e-1cf4-42c2-aa54-e36f7b80a1e1.vsidx +/.vs/Extention/FileContentIndex/f52f8634-b0ca-4955-83a4-e0d437f71198.vsidx +/.vs/slnx.sqlite +*.vsidx diff --git a/.vs/Extention/FileContentIndex/10121bdc-6315-4f6e-94ac-fd1a46abeb7f.vsidx b/.vs/Extention/FileContentIndex/10121bdc-6315-4f6e-94ac-fd1a46abeb7f.vsidx deleted file mode 100644 index 55300f6..0000000 Binary files a/.vs/Extention/FileContentIndex/10121bdc-6315-4f6e-94ac-fd1a46abeb7f.vsidx and /dev/null differ diff --git a/.vs/Extention/FileContentIndex/55fe423a-ecf3-4840-ab4e-afdab2848472.vsidx b/.vs/Extention/FileContentIndex/55fe423a-ecf3-4840-ab4e-afdab2848472.vsidx deleted file mode 100644 index 981854a..0000000 Binary files a/.vs/Extention/FileContentIndex/55fe423a-ecf3-4840-ab4e-afdab2848472.vsidx and /dev/null differ diff --git a/.vs/Extention/FileContentIndex/723f158e-1cf4-42c2-aa54-e36f7b80a1e1.vsidx b/.vs/Extention/FileContentIndex/723f158e-1cf4-42c2-aa54-e36f7b80a1e1.vsidx deleted file mode 100644 index 64cefb3..0000000 Binary files a/.vs/Extention/FileContentIndex/723f158e-1cf4-42c2-aa54-e36f7b80a1e1.vsidx and /dev/null differ diff --git a/.vs/Extention/FileContentIndex/f52f8634-b0ca-4955-83a4-e0d437f71198.vsidx b/.vs/Extention/FileContentIndex/f52f8634-b0ca-4955-83a4-e0d437f71198.vsidx deleted file mode 100644 index 7c6fa3d..0000000 Binary files a/.vs/Extention/FileContentIndex/f52f8634-b0ca-4955-83a4-e0d437f71198.vsidx and /dev/null differ diff --git a/.vs/Extention/v17/.suo b/.vs/Extention/v17/.suo index 81bbe48..151ba1d 100644 Binary files a/.vs/Extention/v17/.suo and b/.vs/Extention/v17/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite deleted file mode 100644 index 90c0daa..0000000 Binary files a/.vs/slnx.sqlite and /dev/null differ diff --git a/manifest.json b/manifest.json index a8ac154..b0d27b0 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Download Manager", - "version": "1.0.2.2", - "manifest_version": 2, + "version": "2.0.0.0", + "manifest_version": 3, "description": "Download Manager browser extension to download files.", "icons": { "16": "icons/icon.png", @@ -10,17 +10,20 @@ "128": "icons/icon.png" }, "permissions":[ - "webRequest", - "webRequestBlocking", + "declarativeNetRequest", + "declarativeNetRequestFeedback", "", "storage", "contextMenus", "tabs" ], - "browser_action": { - "default_popup": "popup/popup.html" + "host_permissions": [ + "*://*.*.*/*.zip" + ], + "background": { + "service_worker": "background.js" }, - "background":{ - "scripts": ["scripts/background.js"] + "action": { + "default_popup": "popup/popup.html" } } \ No newline at end of file diff --git a/scripts/background.js b/scripts/background.js index e926d48..8e02e14 100644 --- a/scripts/background.js +++ b/scripts/background.js @@ -1,638 +1,44 @@ -chrome.contextMenus.create({ - "title": "Download with Download Manager", - "contexts": ["link"], - "onclick": function(info, tab) { - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + info.linkUrl + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - }); - } -}); - -chrome.webRequest.onHeadersReceived.addListener( - // ... your code that checks whether the request should be blocked ... - // (omitted for brevity) +// This file must be placed on the same directory to "manifest.json" +// since below code works as a service worker. - function(details) { - // return {cancel: true}; - - chrome.storage.local.get(['extToggle'], function(result) { - window.toggleExt = result.extToggle; - }); +const ruleId = 1; - if(window.toggleExt == null){ - console.error("Could not determine extension toggle state.\nDefaulting to disabled."); - } - else{ - if(window.toggleExt == true){ - if(details.url.indexOf("www.bing.com/vs/ec/stop.mp3") >= 0 || - details.url.indexOf("www.bing.com/vs/ec/start.mp3") >= 0 || - details.url.indexOf("mp3+") >= 0 || - details.url.indexOf("mp3&") >= 0 || - details.url.indexOf("upload.") >= 0 || - details.url.indexOf("partner.microsoft.com") >= 0 || - details.url.indexOf("adfoc.us") >= 0 || - details.url.indexOf("adloadx") >= 0 || - details.url.indexOf(".pipe.") >= 0 || - details.url.indexOf("chrome-extension://") >= 0 || - details.url.indexOf("exef") >= 0) { - console.warn("Could not download. Download url is in URL blacklist."); - return {cancel: false}; - } - else{ - if(details.url.indexOf('.zip') >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".7z") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".rar") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".iso") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if (details.url.indexOf(".img") >= 0) { - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".exe") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if (details.url.indexOf(".jar") >= 0) { - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".msi") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".aif") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".cda") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".mid") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".midi") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".mp3") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".mpa") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".ogg") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".wav") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".wma") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".wpl") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".mp4") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".vsix") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".py") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".txt") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".log") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".tar") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".rbxl") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".rbxm") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".doc") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".docx") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".ppt") >=0){ - console.log("Blocking request."); - return {cancel: true}; - } - else if(details.url.indexOf(".bin") >=0){ - if(details.url.indexOf(".bing") >=0){ - console.warn("URLs containing .bin like .bing will be picked up as a download. If this happens please file a bug report."); - } - else{ - console.log("Blocking request."); - return {cancel: true}; - } - } - else{ - console.log("Request does not contain any download type so has not been blocked."); - return {cancel: false}; - } - } - } - else { - console.log("Extention is disabled. Request has not been blocked."); - return {cancel: false}; - } +const rules = { + removeRuleIds: [ruleId], + addRules: [{ + id: ruleId, + priority: 1, + condition: { + domains: ["*.*.*/*.zip"], + resourceTypes: ["main_frame", "xmlhttprequest"], + }, + action: { + type: "modifyHeaders", + requestHeaders: [{ + header: "X-DeclarativeNetRequest-Sample", + operation: "set", + value: "request" + }], + responseHeaders: [{ + header: "X-DeclarativeNetRequest-Sample", + operation: "set", + value: "response" + }], } - }, - {urls: [""]}, - ["responseHeaders", "blocking"]); + }], +}; - /* - - else{ - console.log("Request does not contain any download type so has not been blocked."); - } - } +chrome.declarativeNetRequest.updateDynamicRules(rules, () => { + if (chrome.runtime.lastError) { + console.error(chrome.runtime.lastError); + } else { + chrome.declarativeNetRequest.getDynamicRules(rules => console.log(rules)); } - else{ - console.log("Extention is disabled. Request has not been blocked."); - } - }); -}, { - urls: [""], - types: ["main_frame", "sub_frame"] -},*/ - -chrome.webRequest.onBeforeRequest.addListener( - function(details) - { - console.log (details.url); - chrome.storage.local.get(['extToggle'], function(result) { - if(result.extToggle == true){ - if (details.url.indexOf("www.bing.com/vs/ec/stop.mp3") >= 0 || - details.url.indexOf("www.bing.com/vs/ec/start.mp3") >= 0 || - details.url.indexOf("mp3+") >= 0 || - details.url.indexOf("mp3&") >= 0 || - details.url.indexOf("upload.") >= 0 || - details.url.indexOf("partner.microsoft.com") >= 0 || - details.url.indexOf("adfoc.us") >= 0 || - details.url.indexOf("adloadx") >= 0 || - details.url.indexOf(".pipe.") >= 0 || - details.url.indexOf("chrome-extension://") >= 0 || - details.url.indexOf("exef") >= 0) { - console.warn("Could not download " + details.url + ". Download url is in URL blacklist."); - } - else{ - if(details.url.indexOf(".zip") >=0){ - console.log("Request url contains .zip which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.includes(".7z")){ - console.log("Request url contains .7z which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".rar") >=0){ - console.log("Request url contains .rar which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".iso") >=0){ - console.log("Request url contains .iso which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if (details.url.indexOf(".img") >= 0) { - console.log("Request url contains .iso which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".exe") >=0){ - console.log("Request url contains .exe which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if (details.url.indexOf(".jar") >= 0) { - console.log("Request url contains .jar which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".msi") >=0){ - console.log("Request url contains .msi which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".aif") >=0){ - console.log("Request url contains .aif which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".cda") >=0){ - console.log("Request url contains .cda which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".mid") >=0){ - console.log("Request url contains .mid which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".midi") >=0){ - console.log("Request url contains .midi which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".mp3") >=0){ - console.log("Request url contains .mp3 which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".mpa") >=0){ - console.log("Request url contains .mpa which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".ogg") >=0){ - console.log("Request url contains .ogg which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".wav") >=0){ - console.log("Request url contains .wav which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".wma") >=0){ - console.log("Request url contains .wma which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".wpl") >=0){ - console.log("Request url contains .wpl which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".mp4") >=0){ - console.log("Request url contains .mp4 which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".vsix") >=0){ - console.log("Request url contains .visx which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".py") >=0){ - console.log("Request url contains .py which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".txt") >=0){ - console.log("Request url contains .txt which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".log") >=0){ - console.log("Request url contains .log which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".tar") >=0){ - console.log("Request url contains .tar which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".doc") >=0){ - console.log("Request url contains .doc which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".docx") >=0){ - console.log("Request url contains .docx which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".ppt") >=0){ - console.log("Request url contains .ppt which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".rbxl") >=0){ - console.log("Request url contains .rbxl which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".rbxm") >=0){ - console.log("Request url contains .rbxm which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - else if(details.url.indexOf(".bin") >=0){ - if(details.url.indexOf(".bing") >=0){ - console.warn("URLs containing .bin like .bing will be picked up as a download. If this happens please file a bug report."); - } - else{ - console.log("Request url contains .bin which is a download type. Sending to Download Manager."); - chrome.storage.local.get(['port'], function(result) { - try{ - httpGet('http://localhost:' + result.port + '/?url="' + details.url + '"'); - } - catch(err){ - console.error(err); - alert("Failed to send download request to internal server.\nCheck that Download Manager is running and try again."); - } - console.log('Server port value is ' + result.port); - }); - } - } - } - } - else{ - console.log("Extention is disabled. Not sending to Download Manager."); - } - }); - }, - - {urls: [""]}, - - ["blocking"] -); +}); -function httpGet(theUrl) -{ - var xmlHttp = new XMLHttpRequest(); - xmlHttp.open( "GET", theUrl, false ); // false for synchronous request - xmlHttp.send( null ); - return xmlHttp.responseText; -} \ No newline at end of file +// You can use `chrome.declarativeNetRequest.updateSessionRules` instead of `updateDynamicRules`. +// If you use it, the rules are not persisted across browser sessions. +// ==> https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#method-updateSessionRules +// +// Use `getSessionRules` in order to get session-scoped rules. +// ==> https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#method-getSessionRules