aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/enums.js2
-rw-r--r--app/scripts/lib/util.js11
-rw-r--r--app/scripts/platforms/extension.js6
-rw-r--r--app/vendor/trezor/usb-permissions.js3
4 files changed, 18 insertions, 4 deletions
diff --git a/app/scripts/lib/enums.js b/app/scripts/lib/enums.js
index c6d57a1bc..32c0947a3 100644
--- a/app/scripts/lib/enums.js
+++ b/app/scripts/lib/enums.js
@@ -1,6 +1,7 @@
const ENVIRONMENT_TYPE_POPUP = 'popup'
const ENVIRONMENT_TYPE_NOTIFICATION = 'notification'
const ENVIRONMENT_TYPE_FULLSCREEN = 'fullscreen'
+const ENVIRONMENT_TYPE_BACKGROUND = 'background'
const PLATFORM_BRAVE = 'Brave'
const PLATFORM_CHROME = 'Chrome'
@@ -12,6 +13,7 @@ module.exports = {
ENVIRONMENT_TYPE_POPUP,
ENVIRONMENT_TYPE_NOTIFICATION,
ENVIRONMENT_TYPE_FULLSCREEN,
+ ENVIRONMENT_TYPE_BACKGROUND,
PLATFORM_BRAVE,
PLATFORM_CHROME,
PLATFORM_EDGE,
diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js
index ea13b26be..2eb71c0a0 100644
--- a/app/scripts/lib/util.js
+++ b/app/scripts/lib/util.js
@@ -5,6 +5,7 @@ const {
ENVIRONMENT_TYPE_POPUP,
ENVIRONMENT_TYPE_NOTIFICATION,
ENVIRONMENT_TYPE_FULLSCREEN,
+ ENVIRONMENT_TYPE_BACKGROUND,
PLATFORM_FIREFOX,
PLATFORM_OPERA,
PLATFORM_CHROME,
@@ -28,17 +29,21 @@ function getStack () {
* - 'popup' refers to the extension opened through the browser app icon (in top right corner in chrome and firefox)
* - 'responsive' refers to the main browser window
* - 'notification' refers to the popup that appears in its own window when taking action outside of metamask
+ * - 'background' refers to the background page
*
* @returns {string} A single word label that represents the type of window through which the app is being viewed
*
*/
const getEnvironmentType = (url = window.location.href) => {
- if (url.match(/popup.html(?:#.*)*$/)) {
+ const parsedUrl = new URL(url)
+ if (parsedUrl.pathname === '/popup.html') {
return ENVIRONMENT_TYPE_POPUP
- } else if (url.match(/home.html(?:\?.+)*$/) || url.match(/home.html(?:#.*)*$/)) {
+ } else if (parsedUrl.pathname === '/home.html') {
return ENVIRONMENT_TYPE_FULLSCREEN
- } else {
+ } else if (parsedUrl.pathname === '/notification.html') {
return ENVIRONMENT_TYPE_NOTIFICATION
+ } else {
+ return ENVIRONMENT_TYPE_BACKGROUND
}
}
diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js
index 43820515d..d54a8a7b3 100644
--- a/app/scripts/platforms/extension.js
+++ b/app/scripts/platforms/extension.js
@@ -1,6 +1,9 @@
const extension = require('extensionizer')
const {createExplorerLink: explorerLink} = require('etherscan-link')
+const {getEnvironmentType} = require('../lib/util')
+const {ENVIRONMENT_TYPE_BACKGROUND} = require('../lib/enums')
+
class ExtensionPlatform {
//
@@ -35,6 +38,9 @@ class ExtensionPlatform {
extensionURL += `#${route}`
}
this.openWindow({ url: extensionURL })
+ if (getEnvironmentType() !== ENVIRONMENT_TYPE_BACKGROUND) {
+ window.close()
+ }
}
getPlatformInfo (cb) {
diff --git a/app/vendor/trezor/usb-permissions.js b/app/vendor/trezor/usb-permissions.js
index 9de47e0a1..18f70f94f 100644
--- a/app/vendor/trezor/usb-permissions.js
+++ b/app/vendor/trezor/usb-permissions.js
@@ -25,6 +25,7 @@ const switchToPopupTab = (event) => {
return;
}
+ // TODO: remove this query, or add `tabs` permission. This does not work.
// triggered from 'beforeunload' event
// find tab by popup pattern and switch to it
chrome.tabs.query({
@@ -47,4 +48,4 @@ window.addEventListener('message', event => {
}
});
-window.addEventListener('beforeunload', switchToPopupTab); \ No newline at end of file
+window.addEventListener('beforeunload', switchToPopupTab);