Lou*_*sen 10 notification google-chrome chromium
我正在尝试在 Ubuntu 上使用 Google Chrome(或 Chromium)获取本机通知,但到目前为止还没有运气。
我已经尝试过的事情:
我也运行install.sh过(并重新启动了 Chrome):
$ ./install.sh
Native messaging host com.initiated.chrome_libnotify_notifications has been installed.
Run Code Online (Sandbox Code Playgroud)我记得我也尝试过另一个扩展,但我不记得它的名字了。
他们都没有工作。我不断收到 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/"
]
}
Run Code Online (Sandbox Code Playgroud)
编辑:这不是唯一需要进行的更改。该扩展程序依赖于 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) + "/";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12900 次 |
| 最近记录: |