First, to configure permissions in the Manifest.json
"Permissions": [
"tabs", "notifications"
],
Then, call the Chrome desktop notification API in Background.js
//displays the data as a desktop notification to user function _showdataonpage (data) {//display a desktop notification if (window.webkitnotific ations) {var notification = window.webkitNotifications.createNotification (' images/icon.png ',//Icon U
Rl-can be relative ' notice of title! ',//Notification title data//notification body text);
Notification.show ();
After setting 3 seconds, notify the desktop of dismiss settimeout (function () {notification.cancel ();}, 3000);
}else if (chrome.notifications) {var opt = {type: ' Basic ', title: ' Notice of title! ',
Message:data, Iconurl: ' Images/icon.png ',} chrome.notifications.create (', OPT, function (ID) {
settimeout (function () {Chrome.notifications.clear (ID, function () {});
}, 3000);
}); }else{alert (' Pro, your browser doesn't support AH.
'); }
}
On some chrome versions, No Window.webkitnotification objects, in order to be compatible with all chrome versions, add a judgment on unsupported window.webkitnotification versions, using Chrome.notifications