
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
notification-koro1
Advanced tools
H5 notification:一个浏览器桌面通知 npm 包,求 Star
体积不超过 2KB
npm i -S notification-koro1
插件在vue项目中使用的示例:.vue
文件
初始化需要两个参数:title
(通知的标题)、options
(配置),具体信息查阅wiki文章和MDN
import notification from 'notification-koro1'; // 引入npm包
const notificationClass = new notification(title, options); // 初始化
support
在notification-koro1
初始化完毕之后,可以通过support
字段来判断浏览器是否支持notification
API
if (notificationClass.support) {
// 显示通知逻辑,以下所有步骤都要在这里调用
} else {
// 浏览器不支持
}
注册回调事件:notificationEvent
notificationEvent
接收一个对象参数,对象的每个属性值必须都是函数
下面是栗子:
// 点击弹窗的回调
const eventObj = {
// 点击通知回调
onclick: e => {
console.log("点击通知打开百度", e);
window.open("https://www.baidu.com/", "_blank");
},
// 通知显示回调
onshow: e => {
console.log("显示", e);
},
// 通知遇到错误回调
onerror: e => {
console.log("通知报错", e);
},
// 通知关闭回调
onclose: e => {
console.log("关闭通知", e);
}
};
this.notificationClass.notificationEvent(eventObj);
注意:
const userSelectFn = msg => {
if (msg === 'already granted' || msg === 'granted') {
// 随时可以调用通知
return notificationClass.userAgreed();
} else if (msg === 'close') {
// 请求权限通知被关闭
return notificationClass.initNotification(userSelectFn); // 再次调用
} else if(msg === 'denied' || msg === 'already denied') {
// 请求权限当前被拒绝 || 曾经被拒绝
if (msg === "denied") {
console.log("您刚刚拒绝显示通知 请在设置中更改设置");
}else{
console.log("您曾级拒绝显示通知 请在设置中更改设置");
}
}
};
notificationClass.initNotification(userSelectFn); // 请求授权
当用户同意的时候(请求授权的第一个判断),就可以在合适的时间,调用下面的方法来显示通知。
我们可以先请求用户授权,然后在需要的时候再发送通知,微博就是这么做的。
notificationClass.userAgreed();
.vue文件
如果觉得还挺好用的,可以给我点个Star呀
FAQs
(浏览器桌面通知)Html5 Notification npm包
The npm package notification-koro1 receives a total of 110 weekly downloads. As such, notification-koro1 popularity was classified as not popular.
We found that notification-koro1 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.