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); url = chrome.runtime.getURL(url);
} }
return new Promise(resolve => { return new Promise(resolve => {
chrome.tabs.query({url, currentWindow}, tabs => { // API doesn't handle the hash-fragment part
if (tabs.length) { chrome.tabs.query({url: url.replace(/#.*/, ''), currentWindow}, tabs => {
activateTab(tabs[0]).then(resolve); for (const tab of tabs) {
} else { if (tab.url == url) {
activateTab(tab).then(resolve);
return;
}
}
getActiveTab().then(tab => ( getActiveTab().then(tab => (
tab && tab.url == 'chrome://newtab/' tab && tab.url == 'chrome://newtab/'
? chrome.tabs.update({url}, resolve) ? chrome.tabs.update({url}, resolve)
: chrome.tabs.create({url}, resolve) : chrome.tabs.create({url}, resolve)
)); ));
}
}); });
}); });
} }

View File

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