openURL: handle urls with #
This commit is contained in:
parent
4a642f77a5
commit
a2ea1bb1d9
21
messaging.js
21
messaging.js
|
@ -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)
|
||||
));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user