Desktop notifications from content scripts

前端 未结 2 1912
执念已碎
执念已碎 2020-12-29 14:47

I am trying to show a simple desktop notification code from a content script, but it doesn\'t seem to work.. I have added the permissions in the maifest.json file. Is there

2条回答
  •  抹茶落季
    2020-12-29 15:02

    Yes, notifications use Chrome specific API, and the content script is only valid for general javascript etc... The background page is where all chrome specific API's are capable of running... First you'll need to register your background page in the manifest.json file - like this:

     "background_page": "background.html",
    

    Also in the manifest file, Allow the required permissions:

    "permissions": [ "notifications" ],
    

    Then your script in the background page should look like this :

    
    

提交回复
热议问题