我必须重新加载chrome扩展以显示通知
I have to reload chrome extension to show notification
我正在开发我的第一个chrome扩展。我已经实现了Signal R2来显示chrome通知。问题是,如果扩展是idol一段时间,它就会停止显示通知,同时如果我调试background.js(通过打开扩展的后台页面),它就会开始显示通知。
这是我的信号R实现
[HttpGet]
public void SendNotificationYealink(string mac, string ip, string model, string active_url, string active_user, string active_host, string local, string remote, string display_local, string display_remote, string call_id, string action)
{
var context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
context.Clients.All.addNotificationToExtension("Arslan", "Active_User =" + active_user +
", Local =" + local + ", Remote =" + remote + ", Display_Local =" + display_local + ", Display_Remote =" + display_remote + ", Call Id=" + call_id);
}
和我的背景.js
$(function () {
var connection = $.hubConnection();
connection.url = 'http://localhost:8089/signalr';
var notificationHubProxy = connection.createHubProxy('notificationHub');
notificationHubProxy.on('addNotificationToExtension', function (callFrom, phoneNumber) {
var firstRun =
{
type: "basic",
title: callFrom,
message: phoneNumber,
iconUrl: "icon.png"
}
chrome.notifications.create(firstRun);
});
connection.start().done(function () {
console.log('Connection established.');
});
})
显然,一旦执行了一次闭包,闭包中的变量以及notificationHubProxy
及其事件侦听器就会被销毁。
删除代码周围的($(function () { ... })()
包装,它在扩展的后台页面中没有任何作用,因为它在自己的隔离环境中运行,所以不必向任何人隐藏变量。
在不太可能的情况下,这是一种确保后台页面的DOM初始化的方法,并且您实际上在其中有DOM元素,只需在关闭</body>
标记之前将<script src="background.js"></script>
移动到background.html
的末尾。
相关文章:
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- chrome扩展更改主机/域警告
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 从选项页面更新chrome扩展清单权限
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- Chrome扩展:遍历不同的页面并收集数据
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 可以从Chrome扩展修改窗口对象吗
- 从popup.js|Chrome扩展访问DOM
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 在Chrome扩展内部输出Google API调用
- 检查是否存在使用chrome扩展的javascript库
- 从Chrome扩展访问Google Cloud SQL数据库
- Chrome扩展,Chrome.tabs.query的结果未定义
- 为tweet构建chrome扩展
- 在chrome扩展中使用AJAX获取目录中的文件数