Reputation: 4165
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?
Thanks.
Upvotes: 39
Views: 50245
Reputation: 298
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,
)
Upvotes: 4
Reputation: 307
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.
Upvotes: 0
Reputation: 4215
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"
}
}
Upvotes: 7
Reputation: 4137
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();
}
Upvotes: 18