Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening Side Panel with tabId parameter opens side panel on all tabs #1179

Open
belthaZornv opened this issue Jun 10, 2024 · 2 comments
Open

Comments

@belthaZornv
Copy link

⚠️ If you have general Chrome Extensions questions, consider posting to the Chromium Extensions Group or Stack Overflow.

Describe the bug

I'm using:

https://github.com/GoogleChrome/chrome-extensions-samples/blob/main/functional-samples/cookbook.sidepanel-open/script.js

But the sidepanel stays open for all the tabs.

To Reproduce
Steps to reproduce the behavior, or file the issue is found in:

  1. Go to 'cookbook'
  2. Copy and paste the code to your code (background script)
  3. Install and open sidePanel -> sidePanel on all tabs.

Expected behavior

SidePanel only open for the active tab

Screenshots
If applicable, add screenshots to help explain your problem.

Notes
Anything additional here. 🌈

@oliverdunk oliverdunk changed the title Tab specific sidepanel - Cookbook - Not working Opening Side Panel with tabId parameter opens side panel on all tabs Jun 10, 2024
@munr0
Copy link

munr0 commented Oct 14, 2024

Bringing attention to this – using chrome.sidePanel.open({ tabId: sender.tab.id }); still seems to open the tab-specific side panel on the intended tab, but also opens the global tab defined in the "default_path": in manifest.json everywhere else.

@Mohamed3nan
Copy link

Mohamed3nan commented Oct 31, 2024

I saw your comment her #987

--

Here's what finally worked for me:

function openSidePanel(windowId, tabId, scope) {
    const sidePanelPath = 'sidepanel/sidepanel.htmll';
    const options = {
        path: sidePanelPath,
        enabled: true,
        ...(tabId !== undefined ? { tabId } : { windowId })
    };

    if (scope === 'tab-specific' && tabId !== undefined) {
        chrome.sidePanel.setOptions(options, () => {
            chrome.sidePanel.open({ tabId });
        });
    } else {
        chrome.sidePanel.setOptions({ path: sidePanelPath, enabled: true }, () => {
            chrome.sidePanel.open({ windowId });
        });
    }
}

and in the Manifest file remove this:

  "side_panel": {
    "default_path": "sidepanel/sidepanel.html"
  },

finally, if you made any edits to the scope you must reload the extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants