From cda171e3281955a9dbac465ab3441a1db6d94dc2 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 23 May 2018 12:00:38 +0100 Subject: [PATCH] fix: avoid crashing extension in Chrome More context: https://github.com/ipfs-shipyard/ipfs-companion/issues/464 --- add-on/src/popup/quick-upload.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/add-on/src/popup/quick-upload.js b/add-on/src/popup/quick-upload.js index ff1e66fd7..ab6391208 100644 --- a/add-on/src/popup/quick-upload.js +++ b/add-on/src/popup/quick-upload.js @@ -84,6 +84,15 @@ function quickUploadStore (state, emitter) { }) totalSize += file.size } + if (!browser.runtime.id.includes('@')) { + // we are in non-Firefox runtime (we know for a fact that Chrome puts no @ in id) + if (state.ipfsNodeType === 'external' && totalSize >= 134217728) { + // avoid crashing Chrome until the source of issue is fixed in js-ipfs-api + // - https://github.com/ipfs-shipyard/ipfs-companion/issues/464 + // - https://github.com/ipfs/js-ipfs-api/issues/654 + throw new Error('Unable to process payload bigger than 128MiB in Chrome. See: js-ipfs-api/issues/654') + } + } progressHandler(0, totalSize, state, emitter) emitter.emit('render') // TODO: update flag below after wrapping support is released with new js-ipfs @@ -103,8 +112,8 @@ function quickUploadStore (state, emitter) { } catch (err) { console.error('Unable to perform quick upload', err) // keep upload tab and display error message in it - state.message = `Unable to upload to IPFS API: ${err.name ? err.name : err}` - state.progress = '' + state.message = `Unable to upload to IPFS API:` + state.progress = `${err}` emitter.emit('render') } })