event to trigger popup based on content script keyboard shortcut?

4,000 views
Skip to first unread message

Richard Harding

unread,
Jun 20, 2011, 9:16:15 AM6/20/11
to Chromium-extensions
I'm trying to find a method to trigger the popup action of my
extension from a keyboard shortcut injected into the page via a
content script. I can find many people using the content scripts to
perform actions, but I can't find the necessary trick/api call to
popup an extension.

For instance, this example is triggering the tab api to change it's
pinned status:
http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/tabs/pin/

and I've seen others that change the current url based on the injected
shortcut, but the closes I can find to an api call to trigger the
click of an extesion popup is the onClicked event, but that states
that "Fired when a browser action icon is clicked. This event will not
fire if the browser action has a popup." so it seems trying to
manually trigger a 'clicked' event wouldn't work as well.

Am I missing something? Thanks for the pointers.

Rick
https://chrome.google.com/webstore/detail/knnbmilfpmbmlglpeemajjkelcbaaega

Richard Harding

unread,
Jun 20, 2011, 10:06:15 AM6/20/11
to Chromium-extensions


On Jun 20, 9:16 am, Richard Harding <rhard...@mitechie.com> wrote:
> I'm trying to find a method to trigger the popup action of my
> extension from a keyboard shortcut injected into the page via a
> content script. I can find many people using the content scripts to
> perform actions, but I can't find the necessary trick/api call to
> popup an extension.

I did see a reference to using an event to open the popup.html in a
new tab. I tried this out. Unfortunately may plugin is related to the
url of the current tab. So when I trigger the popup.html into a new
tab, the url is off.

I tried to send in the value of the previous tab url via:

chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.url) {
chrome.tabs.getSelected(null, function(tab_obj) {
var opened_from = tab_obj;
chrome.tabs.create({url: "popup.html"},
function (tab_obj) {
var opened = opened_from.url,
title = opened_from.title;
code = "window.onload(function()
{alert('test');};";

alert('calling');
chrome.tabs.executeScript(tab_obj.id,
{'code': code});

});
});
}
}
);

However, I get a permission issue with the executeScript since the url
scheme is chrome-extrension://

I can't add that to the permissions since it's not a valid scheme.

The idea was that I could try to inject some code that knew the url/
title of the previous page into the popup.html.

Are there any workaround to this method I might be able to keep
pursuing?

Thanks

Rick

Arne Roomann-Kurrik

unread,
Jun 20, 2011, 7:34:29 PM6/20/11
to Richard Harding, Chromium-extensions
It's not possible to open an extension popup programatically:

The new window approach should work - in the past I've resorted to using querystrings or hashes as a simple means of passing data to the newly opened window.

For example:

encoded_url = window.btoa(opened);
encoded_title = window.btoa(title);
chrome.tabs.create({url: "popup.html#" + encoded_url + "|" + encoded_title});

then in the popup:

var parts = window.location.hash.substring(1).split('|')
var url = window.atob(parts[0]);
var title = window.atob(parts[1]);

~Arne

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Richard Harding

unread,
Jun 21, 2011, 11:01:06 AM6/21/11
to Chromium-extensions
Thanks Arne, the url passing was the trick I needed. Appreciate the
tip.

Rick

On Jun 20, 7:34 pm, Arne Roomann-Kurrik <kur...@chromium.org> wrote:
> It's not possible to open an extension popup programatically:http://code.google.com/chrome/extensions/faq.html#faq-open-popups
>
> The new window approach should work - in the past I've resorted to using
> querystrings or hashes as a simple means of passing data to the newly opened
> window.
>
> For example:
>
> encoded_url = window.btoa(opened);
> encoded_title = window.btoa(title);
> chrome.tabs.create({url: "popup.html#" + encoded_url + "|" +
> encoded_title});
>
> then in the popup:
>
> var parts = window.location.hash.substring(1).split('|')
> var url = window.atob(parts[0]);
> var title = window.atob(parts[1]);
>
> ~Arne
>
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org.
Reply all
Reply to author
Forward
0 new messages