M
M
michail812021-11-28 18:09:19
Google Chrome
michail81, 2021-11-28 18:09:19

Chrome extension mainfiest v3 servece_worker chrome.tabs.update how to remove one extra operation?

Hello. The mainfiest v3 servece_worker chrome extension goes through the addresses in the list when the tab is updated, the file is injected, executes the logic, sends a message to the worker, new address, new injection

var hrefm="адрес"
async function secondStart () {
    let wcall=false;
    let delCount=0;
    const tab = await chrome.tabs.update({url: hrefm});
    const tabId = tab.id;
    console.log(tabId,wcall);
    if(tab.status!="complete"&&!wcall) await onTabUrlUpdated1(tabId);
        wcall=true;
        console.log(delCount,wcall);
        delCount++;
        const results = await chrome.scripting.executeScript({
            target: {tabId},
            files: ['js/myyinject.js']
        },
        () => {
            console.log("myyinject");
        });
}  
function onTabUrlUpdated1(tabId) {
    return new Promise((resolve, reject) => {
        const onUpdated1 = (id, info) => {
            console.log(info.status);
            id === tabId && info.url && done(true)
        };
        const onRemoved1 = id => id === tabId && done(false);
        chrome.tabs.onUpdated.addListener(onUpdated1);
        chrome.tabs.onRemoved.addListener(onRemoved1);
        function done(ok) {
            chrome.tabs.onUpdated.removeListener(onUpdated1);
            chrome.tabs.onRemoved.removeListener(onRemoved1);
            (ok ? resolve : reject)();
        }});}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question