对于LibNotify,它安装的JSON文件具有错误的扩展名。将扩展ID更新为正确的扩展ID即可解决。
转到.config/google-chrome/NativeMessagingHosts
(对于Google Chrome)或.config/chromium/NativeMessagingHosts
(对于Chromium)。打开文件夹中的JSON文件,请注意,在该allowed_origins
部分中,它允许扩展名ID gphchdpdmccpjmpiilaabhpdfogeiphf
。但是,扩展名ID(至少在我来说是这样,但每个人都应该相同)实际上是epckjefillidgmfmclhcbaembhpdeijg
。
要解决此问题,请用正确的扩展名替换不正确的扩展名,或者在其后添加逗号和正确的扩展名。我个人选择了后者,这是我的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通知的其他浏览器已弃用并删除了Webkit通知。因此,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://flags/#enable-native-notifications
。