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

How to open sidepanel when click the plugin icon in chrome? #570

Closed
zeroxer opened this issue Mar 26, 2024 · 8 comments
Closed

How to open sidepanel when click the plugin icon in chrome? #570

zeroxer opened this issue Mar 26, 2024 · 8 comments
Labels
question A question about usage, not a bug

Comments

@zeroxer
Copy link

zeroxer commented Mar 26, 2024

No description provided.

@aklinker1
Copy link
Collaborator

aklinker1 commented Mar 27, 2024

Edit: See @abegehr response below for the correct way: #570 (comment)


  1. Add an on click listener to your action
    https://developer.chrome.com/docs/extensions/reference/api/action#event-onClicked

  2. Call open
    https://developer.chrome.com/docs/extensions/reference/api/sidePanel#method-open

// entrypoints/background.ts

browser.action.onClicked.addListener(() => browser.sidePanel.open());

browser.action will be undefined if you haven't added the action field to the manifest. You can just set it equal to a empty object

// wxt.config.ts
export default defineConfig({
  manifest: {
    action: {},
  }
})

@abegehr
Copy link

abegehr commented Mar 27, 2024

I ran into the same question. Two remarks:

  1. Make sure your action object in manifest does not have a default_popup field set, otherwise action.onClicked will not be called.
  2. The browser extension api does not include sidePanel, so TSC will complain ("Property 'sidePanel' does not exist on type 'AugmentedBrowser'"), however it still works. Using browser.sidebarAction.toggle() does not work in Chrome (sidebarAction is undefined).

@abegehr
Copy link

abegehr commented Mar 27, 2024

Instead of using the onClicked handler, this is the way to do it from the chrome docs: https://developer.chrome.com/docs/extensions/reference/api/sidePanel#open-action-icon

// Allows users to open the side panel by clicking on the action toolbar icon
browser.sidePanel
  .setPanelBehavior({ openPanelOnActionClick: true })
  .catch((error) => console.error(error));

Again, TSC will complain about browser.sidePanel but it works.

@aklinker1 aklinker1 added question A question about usage, not a bug and removed feature labels Mar 28, 2024
@jtsang4
Copy link

jtsang4 commented Apr 19, 2024

As @abegehr said, the type issue is still exist.

@cloudflypeng
Copy link

and make sure you add
image
into wxt.config.ts because it's not auto

@aklinker1
Copy link
Collaborator

v0.18.2 adds the permission automatically when a side panel entry point is defined

@nileshtrivedi
Copy link

@aklinker1 Thoughts on adding a sidepanel page by default in all templates?

@aklinker1
Copy link
Collaborator

I've consistently said no to adding content to the templates:

So I'm going to say no to this one as well. Templates are a huge time sink to keep up to date and the more features/variants that are added, the more time it takes away from me to add features and fixes to WXT itself.

That said, I'm open to adding community template support to the init command!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about usage, not a bug
Projects
None yet
Development

No branches or pull requests

6 participants