3

My current project requires opening/activating popup.html (browserAction) from content script? I have read a few answers that say, it's not possible because of security concern.

E.g Ans: How can I open my extension's pop-up with JavaScript?

If that's the case, then how Chrome Bookmark Manager extension does it when CTRL+D shortcut is pressed?

Ref: Bookmark Manager Extension

Community
  • 1
  • 1
Arif Billah
  • 157
  • 2
  • 11
  • 1
    Google's extensions are often whitelisted in the source code of chrome and thus can do more stuff. – wOxxOm Mar 21 '17 at 14:20
  • https://stackoverflow.com/questions/12868386/google-chrome-extension-programmatically-open-popup – Josh Lee Mar 21 '17 at 14:52

2 Answers2

3

They're just using the commands interface, with an event name of _execute_page_action (or _execute_browser_action). 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.

Chrome only respects the default shortcut key if it does not conflict with built-in commands, but it makes an exception for extensions that specify chrome_ui_overrides.bookmarks_ui [1], which is currently restricted to the dev channel or the experimental extension by Google.

The Cast extension used to programmatically open its popup, which is the only one I've seen. The API is similarly whitelisted: browserAction.openPopup.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
1

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/pageAction/setPopup

Looks like they are using this.

       a.h.get(c).then(function(a) {
        var c = chrome.pageAction;
        a ? (c.setTitle({
            tabId: b,
            title: Ga
        }),
        c.setIcon({
            tabId: b,
            imageData: {
                19: Cc,
                38: Dc
            }
        })) : (c.setTitle({
            tabId: b,
            title: Ha
        }),
        c.setIcon({
            tabId: b,
            imageData: {
                19: Ec,
                38: Fc
            }
        }));
        c.setPopup({
            tabId: b,
            popup: "popup.html"
        });
        c.show(b)
    })
};

Looking at background_compiled.js

This looks supported but I have not tested. This me briefly looking at the code and just running a search for popup.html. But this might be what you are looking for.

JamesKn
  • 1,035
  • 9
  • 16