37

I have a created a desktop notification using google extension which works great:

icon = '';
    var popup = window.webkitNotifications.createNotification(my notification');
            icon, 'Awesome title', 'Click here to view more. ');
    popup.show();

Is there a way to launch the actual google extension popup.html (as shown on the image below), when the user click on the the desktop notification?

The popup.html The desktop notification

Thanks.

lomse
  • 4,045
  • 6
  • 47
  • 68
  • 5
    possible duplicate of [How can I open my extension's pop-up with JavaScript?](http://stackoverflow.com/questions/10479679/how-can-i-open-my-extensions-pop-up-with-javascript) – Franz Payer Jul 29 '13 at 16:22
  • One approach that might work would be to setup a keyboard shortcut for the pop up in the extension's manifest, then use an executable file to artificially trigger that keyboard shortcut. See [Native Messaging](https://developer.chrome.com/extensions/nativeMessaging) for more info about how to communicate with an executable file from an extension. – Miscreant May 03 '16 at 08:05

2 Answers2

18

Short answer is that you can't, but if you want to open the popup in a new tab instead, this is how you would do it:

Put this before you call show

popup.onclick = function() { 
    chrome.tabs.create({url : "popup.html"}); 
    popup.cancel();
}
Franz Payer
  • 4,069
  • 15
  • 53
  • 77
  • Thanks for the quick reply. Actually the idea is not to open the popup.html in another tab but to launch the exetension as shown on the first image. – lomse Jul 29 '13 at 16:28
  • 5
    See http://stackoverflow.com/questions/10479679/how-can-i-open-my-extensions-pop-up-with-javascript. The google dev explicitly said that they would not allow this functionality. – Franz Payer Jul 29 '13 at 16:30
7

I wanted to add to the comment that Miscreant posted.

One approach that might work would be to setup a keyboard shortcut for the pop up in the extension's manifest, then use an executable file to artificially trigger that keyboard shortcut. See Native Messaging for more info about how to communicate with an executable file from an extension

This is how you set up a shortcut key that opens your extension.

...
"commands": {
"_execute_browser_action": {
    "suggested_key": {
          "default": "Ctrl+Shift+Y"
        }
}

Here's the API on 'commands'.

Ambrose Leung
  • 3,704
  • 2
  • 25
  • 36