How to programmatically open chrome extension popup.html
Asked Answered
D

4

38

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.

Difficile answered 29/7, 2013 at 16:14 Comment(2)
possible duplicate of How can I open my extension's pop-up with JavaScript?Racket
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.Freiburg
R
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();
}
Racket answered 29/7, 2013 at 16:18 Comment(2)
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.Difficile
See #10480179. The google dev explicitly said that they would not allow this functionality.Racket
V
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'.

Virulent answered 14/1, 2018 at 16:0 Comment(3)
I never played with Native Messaging, but I found some documentation here: developer.chrome.com/extensions/nativeMessagingVirulent
Thanks I'll take a look at that! You're a hero :)Oceanic
Has anyone gotten this to work? Are there any issues you've come across/ is it consistent across browsers?Wilkison
H
1

Starting in newer versions of Chrome (127+, expected stable in July 2024), it is possible to open the popup programmatically by calling chrome.action.openPopup().

Note: Because you can't access the chrome.action API from a content script, if you need to open the popup from there you can send a message to the service worker to do it.

chrome.action.openPopup(
  options?: OpenPopupOptions,
  callback?: function,
)
Hindi answered 25/6 at 4:23 Comment(0)
S
0

I think maybe we can only get option page address from chrome extension's manifest json file, then open the address like chrome-extension://<extensionId>/options.html, which extension can not do, but require external program to get option addresses.

Swaine answered 10/9, 2023 at 8:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.