operaopera-extension

Opera API: Is there a way to get the tabs in the current workspace?


Developing an extension, I find myself in the need of closing certain tabs within the current workspace. However, the API makes no distinction of tabs belonging in certain workspaces. A tab has the groupId and windowId properties, but, of course, they're not good indicators of the workspace. So naturally, any tab fulfilling my closing criteria is effectively closed, regardless of their workspace; opposite of my efforts.

A search at the Opera extensions API with the workspace keyword yields no relevant results at all, and neither does the Dev.Opera repository or the issues page. The sidebar API page does not document it either.

Has anyone else stumbled upon this predicament, and found that the answer is not documented? Or could it be that it hasn't been implemented yet, at all? Considering that workspaces are just 15 months old.

EDIT: The changelog for Opera 67.0.3564.0 mentions basic extension API for Workspaces. Well, where is it folks?


Solution

  • From Opera 77 onwards, two additional properties are available: workspaceId and workspaceName.

    The tabs-API now have those additional fields.

    chrome.tabs.onActivated.addListener(async (tab) => {
        const currTab = await chrome.tabs.get(tab.tabId)
        console.log({
            workspaceId: currTab.workspaceId,
            workspaceName: currTab.workspaceName
        })
    })
    

    will output you:

    {workspaceId: '0', workspaceName: 'Default'}
    {workspaceId: '3', workspaceName: 'Gaming'}