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

Proposal: New PanelBehavior for sidePanel openPanelOnContextMenuClick #392

Open
georgehenderson opened this issue May 13, 2023 · 4 comments
Labels
proposal Proposal for a change or new feature

Comments

@georgehenderson
Copy link

When exploring Chrome's new sidePanel api I wish it supported the use case of opening the panel programmatically through a context menu. Imagine a dictionary extension that could open the panel when you highlight a word and select a context menu item.

Here is a naïve example of what the api could look like.

  chrome.contextMenus.create({
    id: "define",
    title: "Define",
    contexts: ["selection"],
  });
  chrome.sidePanel
    .setPanelBehavior({ openPanelOnContextMenuClick: { menuItemId: "define", path: "sidepanel.html" } })
    .catch((error) => console.error(error));

The new PanelBehavior could be called openPanelOnContextMenuClick that is an object with the id from the context menu. I named it menuItemId as this maps to what it is called in the callback for contextMenus.onClicked. Optionally you could add the path to the desired panel if multiple were defined.

@hanguokai
Copy link
Member

Firefox's sidebarAction API supports sidebarAction.open() inside a user action handler.
Chrome doesn't support it. But they heard about this feature feedback.

@georgehenderson
Copy link
Author

Excellent, I missed that conversation. Glad to see that Oliver received that feedback. Having the imperative open method like Firefox would be much nicer as that would allow other types of engagement like being opened from extension injected UI. I figured that was a long shot since have never seen a way to open a popup with other user interactions.

@hanguokai
Copy link
Member

sidePanel.open() will be available in Chrome 116. Source: https://bugs.chromium.org/p/chromium/issues/detail?id=1446022#c14

@fregante
Copy link

fregante commented Jan 12, 2024

I created an issue to suggest sidePanel.toggle(), which would cover use cases like this one.

There are more possible events that could toggle the sidePanel (commands.onCommand,contextMenus.onClicked), so it might not make sense to add them all, especially if they require additional confirmation (unlike the regular openPanelOnActionClick behavior)

chrome.contextMenus.create({
  id: "define",
  title: "Define",
  contexts: ["selection"],
});
chrome.contextMenus.onClicked.addListener(({menuItemId}) => {
  if (menuItemId === 'define') {
    chrome.sidePanel.open();
  }
});

@xeenon xeenon added proposal Proposal for a change or new feature and removed needs-triage labels Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposal for a change or new feature
Projects
None yet
Development

No branches or pull requests

4 participants