简体   繁体   中英

Chrome Extension

I am trying to create a chrome extension that once I click a certain button in my extension, it will highlight the current tab. However, I am having a little bit of trouble.

Right now I have document.getElementById("button").addEventListener("click", function () {} in my JS file, but I can't seem to find a solution on how to colour the current tab. I know something is supposed to go in {}, but I am not exactly sure what. Any help would be appreciated.

As of this writing, there are no methods or properties available as part of the tabs API for Chrome Extensions that allow you to set/modify the color of a tab.

Thus, this is not (currently) possible to accomplish from within the extension context within Chrome.

EDIT : On second thought, this actually might be possible, albeit in a bit of a shoehorned manner. By adding the example function to get the current tab (and then its id property), you can pass it to the chrome.tabs.group() method , then access the returned tabGroup in the callback parameter to set its color property :

chrome.tabs.group(
    options: {
        tabIds: (await getCurrentTab()).id
    },
    callback: function(groupId) {
        chrome.tabGroups.update(
            groupId: groupId,
            updateProperties: {
                color: "red"
            }
        );
    }
);

However, it's not clear if the resulting visual meets your requirements or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM