Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically open chrome extension popup.html

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.htmlThe desktop notification

Thanks.

like image 876
lomse Avatar asked Jul 29 '13 16:07

lomse


People also ask

How do I open Chrome extension popup content script?

They've set the default shortcut to Ctrl+D . Activating this command will perform a click on the page (or browser) action, opening the popup or whatever the action is configured to do.

What is an unpacked Chrome extension?

Chrome extensions can be either packed or unpacked. Packed extensions are a single file with a . crx extension. Unpacked extensions are a directory containing the extension, including a manifest. json file.


2 Answers

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();
}
like image 119
Franz Payer Avatar answered Oct 05 '22 22:10

Franz Payer


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'.

like image 36
Ambrose Leung Avatar answered Oct 05 '22 23:10

Ambrose Leung