1

I'd like to be able to display a styled alert (for example, add image) which the alert dialog is called from the background script of a Chrome Extension (I want to write the code of alert in background.js). Is there any idea how I can display the alert? Is there an APIs Chrome Extension for that?
I have a simple alert without styled :

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab){
    if(changeInfo.status == 'complete' && tab.status == 'complete'){

 alert("This is a simple alert!");

  }   });
  • Use [chrome.notifications](https://developer.chrome.com/extensions/notifications) API – wOxxOm Apr 14 '18 at 11:09
  • @wOxxOm I used it, but it doesn't work! the error: ` Error in event handler for tabs.onUpdated: ReferenceError: webkitNotifications is not defined` – Bashayr Alabdullah Apr 14 '18 at 11:15
  • You weren't using it because webkitNotifications is a different thing. – wOxxOm Apr 14 '18 at 11:16
  • @wOxxOm How can I use this chrome.notifications API ? – Bashayr Alabdullah Apr 14 '18 at 11:17
  • You can use the documentation I've linked or the [demo extensions](https://developer.chrome.com/extensions/samples). – wOxxOm Apr 14 '18 at 11:19
  • @wOxxOm Thank that works, but how can I put the notification on the center of website (change the position)? – Bashayr Alabdullah Apr 14 '18 at 11:32
  • Oh, you'll need a [content script](https://developer.chrome.com/extensions/content_scripts) that adds the corresponding DOM elements and [styles](https://stackoverflow.com/questions/12783217/how-to-really-isolate-stylesheets-in-the-google-chrome-extension). The alternative method is to open a separate window with chrome.windows.create with type: 'popup' and explicitly set position/size. – wOxxOm Apr 14 '18 at 11:33

0 Answers0