1 year ago

#382895

test-img

Maelstrom of nonsense

Chrome extension action chrome.tabs.create() creates three new tabs instead just one in Manifest V3

I’m currently working on a migration Google Chrome extension from Manifest 2 to Manifest 3. I have an issue with it. When I click on the button to open some record in new tab by provided url, Chrome opens it thrice. Using the Manifest 2 it works as expected. Also I logged some data, when I call ChromeSendMessagePromise I get console.log one time with the action CreateTab, but in the background I get it thrice. So how to fix it?

// onClick={openSomeRecord}

const openSomeRecord = () => {
    const someUrl = concatEntityUrl(fooBarUrl, 'Baz', selectedBazEntity.someInfo.id);
    ChromeSendMessagePromise({
        action: MessageActions.CreateTab,
        body: {
            someUrl,
        },
    });
};

// >>>

export const ChromeSendMessagePromise = <T>(
    message: ChromeMessageObject,
): Promise<T> => {
    console.log('Here', message.action); // calls just once
    return chrome.runtime.sendMessage(
        {
            action: message.action,
            data: message.data,
            body: message.body,
            url: message.url,
        },
    );
};

// >>>

case MessageActions.CreateTab:
    chrome.tabs.create({
        url: message.body.someUrl,
    },
        (createTab) => {
            console.log('there', createTab); // calls thrice
            callback(createTab);
        });
    break;

1 Console.log

3 logs

reactjs

google-chrome

google-chrome-extension

chrome-extension-manifest-v3

0 Answers

Your Answer

Accepted video resources