openURL: handle urls with #

This commit is contained in:
tophf 2017-03-27 05:35:10 +03:00
parent 4a642f77a5
commit a2ea1bb1d9
2 changed files with 13 additions and 10 deletions

View File

@ -150,16 +150,19 @@ function openURL({url, currentWindow = true}) {
url = chrome.runtime.getURL(url);
}
return new Promise(resolve => {
chrome.tabs.query({url, currentWindow}, tabs => {
if (tabs.length) {
activateTab(tabs[0]).then(resolve);
} else {
getActiveTab().then(tab => (
tab && tab.url == 'chrome://newtab/'
? chrome.tabs.update({url}, resolve)
: chrome.tabs.create({url}, resolve)
));
// API doesn't handle the hash-fragment part
chrome.tabs.query({url: url.replace(/#.*/, ''), currentWindow}, tabs => {
for (const tab of tabs) {
if (tab.url == url) {
activateTab(tab).then(resolve);
return;
}
}
getActiveTab().then(tab => (
tab && tab.url == 'chrome://newtab/'
? chrome.tabs.update({url}, resolve)
: chrome.tabs.create({url}, resolve)
));
});
});
}

View File

@ -258,7 +258,7 @@ function openEditorOnMiddleclick(event) {
function openURLandHide(event) {
event.preventDefault();
openURL({url: event.target.href})
openURL({url: this.href})
.then(close);
}