Skip to content

Commit

Permalink
Optimize experience of opening a new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sylingd committed Jan 17, 2018
1 parent 35ff030 commit 6ff4f42
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions scripts/background.js
Expand Up @@ -239,14 +239,19 @@ function autoUpdateStyles() {

function openURL(options, sendResponse) {
delete options.method;
getActiveTab((tab) => {
// re-use an active new tab page
// Firefox may have more than 1 newtab url, so check all
var isNewTab = false;
if (tab.url.indexOf('about:newtab') === 0 || tab.url.indexOf('about:home') === 0) {
isNewTab = true;
browser.tabs.query({currentWindow: true, url: options.url}).then((tabs) => {
if (tabs.length) {
browser.tabs.update(tabs[0].id, {
"active": true
}).then(sendResponse);
} else {
getActiveTab((tab) => {
// re-use an active new tab page
// Firefox may have more than 1 newtab url, so check all
const isNewTab = tab.url.indexOf('about:newtab') === 0 || tab.url.indexOf('about:home') === 0 || tab.url.indexOf('chrome://newtab/') === 0;
browser.tabs[isNewTab ? "update" : "create"](options).then(sendResponse);
});
}
browser.tabs[isNewTab ? "update" : "create"](options).then(sendResponse);
});
}

Expand Down

0 comments on commit 6ff4f42

Please sign in to comment.