Skip to content

Commit a219d2b

Browse files
quevas13Emanuele D'Agostinilidel
authored
fix: regression in HTTP recovery of background tabs (#915)
Co-authored-by: Emanuele D'Agostini <emanuele.d'[email protected]> Co-authored-by: Marcin Rataj <[email protected]>
1 parent 832c602 commit a219d2b

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

add-on/src/lib/ipfs-request.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru
414414

415415
// Chromium bug: sometimes tabs.update does not work from onCompleted,
416416
// we run additional update after 1s just to be sure
417-
setTimeout(() => browser.tabs.update({ url: fixedUrl }), 1000)
417+
setTimeout(() => browser.tabs.update(request.tabId, { url: fixedUrl }), 1000)
418418

419-
return browser.tabs.update({ url: fixedUrl })
419+
return browser.tabs.update(request.tabId, { url: fixedUrl })
420420
}
421421

422422
if (isRecoverable(request, state, ipfsPathValidator)) {
@@ -616,7 +616,7 @@ async function updateTabWithURL (request, redirectUrl, browser) {
616616
// Do nothing if the URL remains the same
617617
if (request.url === redirectUrl) return
618618

619-
return browser.tabs.update({
619+
return browser.tabs.update(request.tabId, {
620620
active: true,
621621
url: redirectUrl
622622
})

test/functional/lib/ipfs-request-gateway-recover.test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const createDnslinkResolver = require('../../../add-on/src/lib/dnslink')
1111
const { createIpfsPathValidator } = require('../../../add-on/src/lib/ipfs-path')
1212
const { optionDefaults } = require('../../../add-on/src/lib/options')
1313

14-
const url2request = (url, type = 'main_frame') => {
15-
return { url, type }
14+
const url2request = (url, type = 'main_frame', tabId = new Date().valueOf()) => {
15+
return { url, type, tabId }
1616
}
1717
const urlRequestWithStatus = (url, statusCode = 200, type = 'main_frame') => {
1818
return { ...url2request(url, type), statusCode }
@@ -54,7 +54,7 @@ describe('requestHandler.onCompleted:', function () { // HTTP-level errors
5454
it('should redirect to default subdomain gateway on broken subdomain gateway request', async function () {
5555
const request = urlRequestWithStatus('http://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.brokenexample.com/wiki/', 500)
5656
await requestHandler.onCompleted(request)
57-
assert.ok(browser.tabs.update.withArgs({ url: 'https://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.dweb.link/wiki/', active: true }).calledOnce, 'tabs.update should be called with default subdomain gateway URL')
57+
assert.ok(browser.tabs.update.withArgs(request.tabId, { url: 'https://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.dweb.link/wiki/', active: true }).calledOnce, 'tabs.update should be called with default subdomain gateway URL')
5858
})
5959
it('should do nothing if broken request is a non-IPFS request', async function () {
6060
const request = urlRequestWithStatus('https://wikipedia.org', 500)
@@ -89,7 +89,7 @@ describe('requestHandler.onCompleted:', function () { // HTTP-level errors
8989
it('should recover from unreachable third party public gateway by reopening on the public gateway', async function () {
9090
const request = urlRequestWithStatus('https://nondefaultipfs.io/ipfs/QmYbZgeWE7y8HXkH8zbb8J9ddHQvp8LTqm6isL791eo14h', 500)
9191
await requestHandler.onCompleted(request)
92-
assert.ok(browser.tabs.update.withArgs({ url: 'https://ipfs.io/ipfs/QmYbZgeWE7y8HXkH8zbb8J9ddHQvp8LTqm6isL791eo14h', active: true }).calledOnce, 'tabs.update should be called with IPFS default public gateway URL')
92+
assert.ok(browser.tabs.update.withArgs(request.tabId, { url: 'https://ipfs.io/ipfs/QmYbZgeWE7y8HXkH8zbb8J9ddHQvp8LTqm6isL791eo14h', active: true }).calledOnce, 'tabs.update should be called with IPFS default public gateway URL')
9393
})
9494
})
9595

@@ -153,7 +153,7 @@ describe('requestHandler.onErrorOccurred:', function () { // network errors
153153
it('should redirect to default subdomain gateway on failed subdomain gateway request', async function () {
154154
const request = urlRequestWithStatus('http://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.brokenexample.com/wiki/', 500)
155155
await requestHandler.onErrorOccurred(request)
156-
assert.ok(browser.tabs.update.withArgs({ url: 'https://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.dweb.link/wiki/', active: true }).calledOnce, 'tabs.update should be called with default subdomain gateway URL')
156+
assert.ok(browser.tabs.update.withArgs(request.tabId, { url: 'https://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.dweb.link/wiki/', active: true }).calledOnce, 'tabs.update should be called with default subdomain gateway URL')
157157
})
158158
it('should do nothing if failed request is a non-IPFS request', async function () {
159159
const request = urlRequestWithNetworkError('https://wikipedia.org')
@@ -179,7 +179,7 @@ describe('requestHandler.onErrorOccurred:', function () { // network errors
179179
it('should recover from unreachable third party public gateway by reopening on the public gateway', async function () {
180180
const request = urlRequestWithNetworkError('https://nondefaultipfs.io/ipfs/QmYbZgeWE7y8HXkH8zbb8J9ddHQvp8LTqm6isL791eo14h')
181181
await requestHandler.onErrorOccurred(request)
182-
assert.ok(browser.tabs.update.withArgs({ url: 'https://ipfs.io/ipfs/QmYbZgeWE7y8HXkH8zbb8J9ddHQvp8LTqm6isL791eo14h', active: true }).calledOnce, 'tabs.update should be called with IPFS default public gateway URL')
182+
assert.ok(browser.tabs.update.withArgs(request.tabId, { url: 'https://ipfs.io/ipfs/QmYbZgeWE7y8HXkH8zbb8J9ddHQvp8LTqm6isL791eo14h', active: true }).calledOnce, 'tabs.update should be called with IPFS default public gateway URL')
183183
})
184184
it('should recover from unreachable HTTP server by reopening DNSLink on the active gateway', async function () {
185185
state.dnslinkPolicy = 'best-effort'
@@ -188,7 +188,7 @@ describe('requestHandler.onErrorOccurred:', function () { // network errors
188188
const expectedUrl = 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org/'
189189
const request = urlRequestWithNetworkError('https://en.wikipedia-on-ipfs.org/')
190190
await requestHandler.onErrorOccurred(request)
191-
assert.ok(browser.tabs.update.withArgs({ url: expectedUrl, active: true }).calledOnce, 'tabs.update should be called with DNSLink on local gateway URL')
191+
assert.ok(browser.tabs.update.withArgs(request.tabId, { url: expectedUrl, active: true }).calledOnce, 'tabs.update should be called with DNSLink on local gateway URL')
192192
dnslinkResolver.clearCache()
193193
})
194194
it('should recover from failed DNS for .eth opening it on EthDNS gateway at .eth.link', async function () {
@@ -199,7 +199,7 @@ describe('requestHandler.onErrorOccurred:', function () { // network errors
199199
const expectedUrl = 'https://almonit.eth.link/'
200200
const request = urlRequestWithNetworkError('https://almonit.eth', dnsFailure)
201201
await requestHandler.onErrorOccurred(request)
202-
assert.ok(browser.tabs.update.withArgs({ url: expectedUrl, active: true }).calledOnce, 'tabs.update should be called with ENS resource on local gateway URL')
202+
assert.ok(browser.tabs.update.withArgs(request.tabId, { url: expectedUrl, active: true }).calledOnce, 'tabs.update should be called with ENS resource on local gateway URL')
203203
dnslinkResolver.clearCache()
204204
})
205205
})

test/functional/lib/ipfs-request-workarounds.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ describe('modifyRequest processing', function () {
193193
browser.tabs.update.flush()
194194
assert.ok(browser.tabs.update.notCalled)
195195
modifyRequest.onCompleted(request)
196-
assert.ok(browser.tabs.update.withArgs({ url: fixedDNSLinkUrl }).calledOnce)
196+
assert.ok(browser.tabs.update.withArgs(request.tabId, { url: fixedDNSLinkUrl }).calledOnce)
197197
browser.tabs.update.flush()
198198
})
199199
})

0 commit comments

Comments
 (0)