From 85f7af3990b59df55ad0f506d16496ded17c8601 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 29 Sep 2017 00:40:02 +0200 Subject: [PATCH] fix: optimize mayContainUnhandledIpfsProtocol This mostly means that we ignore XHR requests. --- add-on/src/lib/common.js | 4 +--- test/unit/01-onBeforeRequest.test.js | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/add-on/src/lib/common.js b/add-on/src/lib/common.js index 98148e38e..17fb1c018 100644 --- a/add-on/src/lib/common.js +++ b/add-on/src/lib/common.js @@ -149,9 +149,7 @@ function normalizedWebPlusRequest (request) { const unhandledIpfsRE = /=(?:web%2B|)(ipfs(?=%3A%2F%2F)|ipns(?=%3A%2F%2F)|dweb(?=%3A%2Fip[f|n]s))%3A(?:%2F%2F|%2F)([^&]+)/ function mayContainUnhandledIpfsProtocol (request) { - // TODO: run only for google, bing, duckduckgo etc - // TODO: add checkbox under experiments - return request.url.includes('%3A%2F') + return request.type === 'main_frame' && request.url.includes('%3A%2F') } function unhandledIpfsPath (requestUrl) { diff --git a/test/unit/01-onBeforeRequest.test.js b/test/unit/01-onBeforeRequest.test.js index 42cd2c3a2..0f4f9e9e2 100644 --- a/test/unit/01-onBeforeRequest.test.js +++ b/test/unit/01-onBeforeRequest.test.js @@ -5,7 +5,7 @@ var sandbox const url2request = (string) => { - return {url: string} + return {url: string, type: 'main_frame'} } describe('onBeforeRequest', function () { @@ -173,5 +173,9 @@ describe('onBeforeRequest', function () { const request = url2request('https://duckduckgo.com/?q=foo%3A%2Fbar%3FargTest%23hashTest&foo=bar') should.not.exist(onBeforeRequest(request)) }) + it('should not be normalized if request.type != main_frame', function () { + const xhrRequest = {url: 'https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar', type: 'xmlhttprequest'} + should.not.exist(onBeforeRequest(xhrRequest)) + }) }) })