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

后端 未结 2 483
天涯浪人
天涯浪人 2021-02-08 05:07

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

2条回答
  •  野的像风
    2021-02-08 05:47

    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.

提交回复
热议问题