Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open the default popup from context menu in a chrome extension

I have developed a chrome extension that opens a popup when I click on the icon near the address bar. Everything works fine, however I want to add some functionality to it. So I thought I'd also add a context menu item so that the user can simply search for the highlighted word. I want the popup to showup when the user clicks on the item in the context menu(the default popup in the top right corner and not a new popup window or a new tab).

Can I have this functionality? If yes, how do I implement it?

like image 479
Annihilator8080 Avatar asked Jul 25 '13 07:07

Annihilator8080


People also ask

How do I add a pop up extension to Chrome?

So, to set your popup, you would call it like this: chrome. browserAction. setPopup({popup: "logged_in.

How do I open an extension menu?

Click the box to the right of the “Extensions Toolbar Menu” option and select “Enabled.” You'll have to relaunch Chrome before your settings take effect. Click the “Relaunch Now” button to restart your web browser. Chrome will reopen all your open tabs, but be sure to save your work first.


1 Answers

You can't make the popup page show programmatically as if the user clicked it.

However, you can still have something display based on the background script / content menu click. There are 4 main options for your background script:

  1. Open a new tab to the popup.html page
  2. Programmatic injection of javascript to construct a popup-like dialog on the page
  3. Content script message passing to do the same as above, using a running content-script.
  4. Use the notifications API for a simple minimally stylized message to the user.

Options 2, 3, 4 will allow the user to stay on their tab without any navigation. The notifications API route is the simplest to use if you just want some quick notification to the user, and there are fewer security snags. 2 and 3 require more book-keeping, but you can make the dialog look like your popup.

like image 50
Tyler Peryea Avatar answered Sep 28 '22 07:09

Tyler Peryea