From b07bbc14e1dc745543c7c95d6a846a789fbf2f81 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 25 Jul 2016 13:46:33 -0700 Subject: [PATCH] Clean up extension polyfill abstraction --- app/scripts/contentscript.js | 21 +++++++++++++-------- app/scripts/lib/extension-instance.js | 7 +------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 43c48dd93..d85675e61 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -9,14 +9,19 @@ if (shouldInjectWeb3()) { } function setupInjection(){ - // inject in-page script - var scriptTag = document.createElement('script') - var urlGetter = extension.extension || chrome.extension - scriptTag.src = urlGetter.getURL('scripts/inpage.js') - scriptTag.onload = function () { this.parentNode.removeChild(this) } - var container = document.head || document.documentElement - // append as first child - container.insertBefore(scriptTag, container.children[0]) + try { + + // inject in-page script + var scriptTag = document.createElement('script') + scriptTag.src = extension.extension.getURL('scripts/inpage.js') + scriptTag.onload = function () { this.parentNode.removeChild(this) } + var container = document.head || document.documentElement + // append as first child + container.insertBefore(scriptTag, container.children[0]) + + } catch (e) { + console.error('Metamask injection failed.', e) + } } function setupStreams(){ diff --git a/app/scripts/lib/extension-instance.js b/app/scripts/lib/extension-instance.js index eeab6c6d0..e0e7c948b 100644 --- a/app/scripts/lib/extension-instance.js +++ b/app/scripts/lib/extension-instance.js @@ -24,14 +24,9 @@ const apis = [ function Extension () { const _this = this - let global = window - - if (window.chrome) { - global = window.chrome - } apis.forEach(function (api) { - _this[api] = global[api] + _this[api] = chrome ? chrome[api] : window[api] || browser.extension[api] }) }