Show notifications in chrome extension

I am writing my first Chrome extension. In my Chrome extension, I added an option in the right-click context menu.

chrome.contextMenus.create({ "id": "MyExntesion", "title": "My Extension", "type": "normal", "contexts": ["image"], "onclick": this.handleClick }); 

In my handleClick method, I want to show a notification. This notification should appear in the upper right corner of the browser window, which only confirms that the user clicked on the context menu. How can I do it?

I did some research, but did not find anything useful. https://developer.chrome.com/extensions/notifications this indicates a notification in the system tray, where https://developer.chrome.com/extensions/browserAction#method-setPopup allows you to create new pop-ups, but they only appear when clicking on the extension icon.

+13
javascript google-chrome google-chrome-extension google-chrome-app
source share
1 answer

There are three main ways to display notifications in Chrome.

1) The above chrome.notifications API . It will show a toast (not just an indication of a systray), but you, as a developer, have little to say about how it looks. Use overview here .

Chrome notification

2) Standard HTML notification API . Chrome looks similar to chrome.notifications , with the exception of less control over formatting and is not controlled by the Chrome notification center. Use overview here .

3) If you really want to control how it is displayed, the most invasive and complex way is to embed your user interface in all pages using a content script.

If you do this, you will encounter several problems:

  • In general, it is more difficult to design the user interface yourself;
  • The user interface will be limited to the web browser;
  • CSS can bleed from the page and spoil your user interface (although the Shadow DOM may be the answer);
  • You need general permissions for “data on all web pages” to show your user interface. This scares users.

However, if you decide to go this route, here is a question that might help: Chrome content scripts with a user interface

+32
source share

All Articles