mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
24 lines
514 B
JavaScript
24 lines
514 B
JavaScript
function notifyUser(user) {
|
|
browser.notifications.create({
|
|
"type": "basic",
|
|
"title": "Google info",
|
|
"message": `Hi ${user.name}`
|
|
});}
|
|
|
|
function logError(error) {
|
|
console.error(`Error: ${error}`);
|
|
}
|
|
|
|
/**
|
|
When the button's clicked:
|
|
- get an access token using the identity API
|
|
- use it to get the user's info
|
|
- show a notification containing some of it
|
|
*/
|
|
browser.browserAction.onClicked.addListener(() => {
|
|
getAccessToken()
|
|
.then(getUserInfo)
|
|
.then(notifyUser)
|
|
.catch(logError);
|
|
});
|