queryUrl expected url

This commit is contained in:
2020-01-10 16:35:57 +08:00
parent 0e62d914c1
commit 6134289d0a

View File

@ -86,10 +86,10 @@ function redirectTab(tab, url) {
action: ACTION_GOTO_URL,
url: url
}
sendMessage(tab, req, `Goto url: ${url}`);
return sendMessage(tab, req, `Goto url: ${url}`);
}
})
.then(() => queryUrl(tab, curUrl, 'Check if tab url matches expected...'))
.then(() => queryUrl(tab, url, 'Check if tab url matches expected...'))
}
/**
@ -125,14 +125,14 @@ function reportIn(tab) {
/**
* get the url of the target tab
* @param {any} tab target tab
* @param {string} urlExcluded if specified, queryUrl resolves only when response not equals to urlExcluded
* @param {string} expected if specified, queryUrl resolves only when tab url equals to expected
* @returns {Promise<string>} a promise of the url
*/
function queryUrl(tab, urlExcluded, log) {
function queryUrl(tab, expected, log) {
let req = {
action: ACTION_QUERY_URL
}
let cond = url => url && (!urlExcluded || (urlExcluded && urlExcluded != url));
let cond = url => url && (!expected || (expected && expected == url));
return sendMessage(tab, req, log, cond);
}