激活Chrome原生通知
我试图在Ubuntu上使用谷歌浏览器(或Chromium)来获取原生通知,但到目前为止还没有运气。
我已经尝试过的事情:
-
Chrome中的Libnotify通知
我也运行了
install.sh
(并重启了Chrome):$ ./install.sh Native messaging host com.initiated.chrome_libnotify_notifications has been installed.
-
Linux本机通知
- Chromify-OSD
我记得我也尝试了另一个扩展,但我不记得它的名字。
他们都没有工作。 我一直收到Chrome本身的正常通知。
我在Ubuntu 14.04 x64上使用Google Chrome 34.0.1847.137。
谁能告诉我如何让这个工作?
对于LibNotify,它安装的JSON文件具有不正确的扩展ID。 将扩展ID更新为正确的扩展ID可以解决问题。
转到.config/google-chrome/NativeMessagingHosts
(适用于Google Chrome)或.config/chromium/NativeMessagingHosts
(适用于Chromium)。 打开文件夹中的JSON文件,注意在allowed_origins
部分中,它允许扩展ID gphchdpdmccpjmpiilaabhpdfogeiphf
。 但是,扩展ID(至少在我的情况下,但对每个人来说应该是相同的)实际上是epckjefillidgmfmclhcbaembhpdeijg
。
要解决此问题,请使用正确的扩展ID替换错误的扩展ID,或者在其后添加逗号和正确的扩展ID。 我个人选择了后一个选项,这就是我的JSON文件的样子:
{ "name": "com.initiated.chrome_libnotify_notifications", "description": "Libnotify Notifications in Chrome", "path": path to the location of install.sh, "type": "stdio", "allowed_origins": [ "chrome-extension://gphchdpdmccpjmpiilaabhpdfogeiphf/", "chrome-extension://epckjefillidgmfmclhcbaembhpdeijg/" ] }
编辑:这不是唯一需要做出的改变。 该扩展程序依赖于Webkit通知,这些通知在Chrome(ium)中被弃用和删除,可能还有其他浏览器支持HTML5通知。 因此,需要更新google-chrome/default/Extensions/epckjefillidgmfmclhcbaembhpdeijg/1.0_0/notify_hook.js
。 我为此编写了一个简短的脚本,但它除了显示通知外,还打破了大部分标准。 使用以下内容替换文件中的所有内容(为仍使用window.webkitNotifications
和(希望)改进的图像支持的站点添加了基本支持)(添加了权限支持):
OriginalNotification = Notification Notification = function(title, properties) { if (Notification.permission != "granted") { if (this.onError) { this.onError(); } return; } if (!properties.hasOwnProperty("body")) { properties["body"] = ""; } if (!properties.hasOwnProperty("icon")) { properties["icon"] = ""; } if (properties["icon"]) { properties["icon"] = getBaseURL() + properties["icon"]; } document.getElementById('libnotify-notifications-transfer-dom-area').innerText = JSON.stringify({title:title, body:properties["body"], iconUrl:properties["icon"]}); var event = document.createEvent("UIEvents"); event.initUIEvent("change", true, true); document.getElementById('libnotify-notifications-transfer-dom-area').dispatchEvent(event); if (this.onShow) { this.onShow(); } }; Object.defineProperty(Notification, "permission", { get: function() { return OriginalNotification.permission; }, set: undefined }); Notification.requestPermission = function(callback) { OriginalNotification.requestPermission(callback); } window.webkitNotifications = {} window.webkitNotifications.checkPermission = function() { return 0; } window.webkitNotifications.createNotification = function(image, title, body) { if (image) { image = getBaseURL() + image; } document.getElementById('libnotify-notifications-transfer-dom-area').innerText = JSON.stringify({title:title, body:body, iconUrl:image}); var event = document.createEvent("UIEvents"); event.initUIEvent("change", true, true); document.getElementById('libnotify-notifications-transfer-dom-area').dispatchEvent(event); } function getBaseURL() { return location.protocol + "//" + location.hostname + (location.port && ":" + location.port) + "/"; }
现在,在安装Chrome 35后,它默认在Unity上运行
http://www.webupd8.org/2014/05/google-chrome-stable-35-for-linux.html