availablity check before run on active tab

This commit is contained in:
2020-01-11 20:40:25 +08:00
parent 341abebc66
commit f1cf32b83a
3 changed files with 20 additions and 6 deletions

View File

@ -110,16 +110,17 @@ function extractTabData(tab, itemsSelector, fieldSelectors) {
}
/**
* get report in from the target tab, usually used to detect if the content script is ready.
* ping target tab, usually used to detect if the content script is ready.
* @param {any} tab target tab
* @returns {Promise<string>} a promise of the report in message
* @returns {Promise<boolean>} a promise of boolean value indicates if ping success
*/
function reportIn(tab) {
async function ping(tab, count = 1) {
let req = {
action: ACTION_REPORT_IN
}
let cond = r => r == req.action;
return sendMessage(tab, req, 'Check tab availability...', cond);
let pong = await sendMessage(tab, req, 'Check tab availability...', cond, 1000, count).catch(() => { });
return pong == ACTION_REPORT_IN;
}
/**