I'm trying to get native notifications to work using Google Chrome (or Chromium) on Ubuntu, but no luck so far.

Things I've tried already:

And I remember I've tried another extension as well but I don't remember its name.

None of them work. I keep getting the normal notifications of Chrome itself.

I'm using Google Chrome 34.0.1847.137 on Ubuntu 14.04 x64.

Can someone tell me how to get this working?

  • 1
    The latest version of Google Chrome Stable (59 as now) supports the Enable Native Notifications flag, which works just perfectly on Gnome Shell. It's available via chrome://flags/#enable-native-notifications. – emi Jul 5 '17 at 21:23
up vote 10 down vote accepted
+100

For LibNotify, the JSON file that it installs has the incorrect extension ID. Updating the extension ID to the correct one fixes it.

Go to .config/google-chrome/NativeMessagingHosts (for Google Chrome) or .config/chromium/NativeMessagingHosts (for Chromium). Open up the JSON file in the folder, and notice that in the allowed_origins section, it allows the extension ID gphchdpdmccpjmpiilaabhpdfogeiphf. However, the extension ID (at least in my case, but it should be the same for everyone) is actually epckjefillidgmfmclhcbaembhpdeijg.

To fix this, either replace the incorrect extension ID with the correct one, or add a comma and the correct extension ID after it. I personally chose the latter option, and here's what my JSON file looks like:

{
  "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/"
  ]
}

EDIT: That's not the only change that needs to be made. The extension relies on Webkit notifications, which were deprecated and removed in Chrome(ium) and likely other browsers in favor of HTML5 notifications. Therefore, google-chrome/default/Extensions/epckjefillidgmfmclhcbaembhpdeijg/1.0_0/notify_hook.js needs to be updated. I've written a short script for this, but it breaks most of the standard except for displaying the notification. Replace everything in the file with the following (added basic support for sites still using window.webkitNotifications and (hopefully) improved image support) (permissions support added):

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) + "/";
}
  • 1
    It's working and the CPU usage seems to have solved itself. However, still doesn't work in the application I want (Webogram). But thank you very much for your answer and effort and I'll just wait for Chrome to support native notifications! – Louis Matthijssen May 16 '14 at 12:51
  • Please see my comment below, works by default on Chrome 35 – Konstigt May 25 '14 at 16:16
  • @Konstigt: It's not that notifications weren't working; it's that the notifications weren't native Linux notifications, and existing solutions (at least the first two links above) used the deprecated method. (I personally don't blame Chrome(ium) for this.) – saiarcot895 May 25 '14 at 16:46
  • I have no .config/chromium/NativeMessagingHosts folder. – umpirsky Oct 31 '14 at 15:21
  • 3
    Man, you really should write your own plugin and post it onto Google Store. If you aren't eager for paying 5$ for registering, then I can do it for you. – Błażej Michalik Jun 11 '16 at 20:59

Now it works on Unity by default after installing Chrome 35

http://www.webupd8.org/2014/05/google-chrome-stable-35-for-linux.html

  • 6
    Those are not Unity notifications. It's just a new skin for Chrome's notifications. – Louis Matthijssen May 25 '14 at 16:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.