From 7f6712088b2601fb9e3be8b07b04c25be0e2f3ca Mon Sep 17 00:00:00 2001 From: dessant Date: Wed, 11 Dec 2019 21:15:04 +0200 Subject: [PATCH] chore: support openerTabId --- src/utils/common.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/utils/common.js b/src/utils/common.js index 9f71050..9dee8d8 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -2,11 +2,21 @@ import browser from 'webextension-polyfill'; const getText = browser.i18n.getMessage; -function createTab(url, {index, active = true} = {}) { +async function createTab( + url, + {index = null, active = true, openerTabId = null} = {} +) { const props = {url, active}; - if (typeof index !== 'undefined') { + if (index !== null) { props.index = index; } + if ( + openerTabId !== null && + openerTabId !== browser.tabs.TAB_ID_NONE && + !(await isAndroid()) + ) { + props.openerTabId = openerTabId; + } return browser.tabs.create(props); } @@ -18,4 +28,9 @@ async function getActiveTab() { return tab; } +async function isAndroid() { + const {os} = await browser.runtime.getPlatformInfo(); + return os === 'android'; +} + export {getText, createTab, getActiveTab};