Skip to content

Improve sidePanel trigger example for production usage best practices #1480

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

Open
chostudio opened this issue May 23, 2025 · 4 comments
Open
Assignees

Comments

@chostudio
Copy link
Contributor

Relevant Line

https://github.com/GoogleChrome/chrome-extensions-samples/blob/20d36c778028f25fb139b83fdd9910b530bd9ea2/functional-samples/ai.gemini-on-device/background.js

Describe the bug

Currently, the side panel is configured as:

chrome.sidePanel
  .setPanelBehavior({ openPanelOnActionClick: true })
  .catch((error) => console.error(error));

Although it works as expected in a dev environment, in production environments this behavior does not open the side panel when users click the pinned extension icon. Users would have to right-click and select "Open Side Panel," which is not intuitive.

Expected behavior

Potential users expect to be able to open the side panel directly by clicking the pinned extension icon once, without needing to right-click > "Open Side Panel" in production.

Suggested Fix

Developers should see an example that will follow best practices for production use.

Update background.js to wrap the code in a Chrome onClick listener:

chrome.action.onClicked.addListener(async (tab) => {
  chrome.sidePanel
    .setPanelBehavior({ openPanelOnActionClick: true })
    .catch((error) => console.error(error));
});
@chostudio
Copy link
Contributor Author

May I be assigned this issue to make a PR for it?

@jamalimubashirali
Copy link

@chostudio what this issue is all about, can you give me the direct insights because right know I can't get this.

@oliverdunk
Copy link
Member

Hi @chostudio, feel free to open a PR. I wouldn't set the behavior in the action.onClicked event, since by the time that has fired the click is already being handled. However, moving it to a chrome.runtime.onInstalled listener might make sense.

@chostudio
Copy link
Contributor Author

made a PR for this issue here: #1483

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