Context menu, why doesn't this work?

1,375 views
Skip to first unread message

Oscar Fröberg

unread,
Aug 5, 2010, 5:00:37 AM8/5/10
to Chromium-extensions
This should be pretty straightforward but whatever I try I can't get a
right click menu option too show. What am I doing wrong?

Chrome version 6.0.472.14 dev (Windows XP)

manifest.json

{
"name": "My First Extension",
"version": "1.0",
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png"
},
"background_page": "background.html",
"permissions": [
"contextMenus","tabs"
]
}

background.html

var url = "http://www.google.com";

chrome.contextMenu.create({"title": "Clickmeplz", "onclick":
chrome.tabs.create({"goooogle": url})});

Mohamed Mansour

unread,
Aug 5, 2010, 11:16:55 PM8/5/10
to Oscar Fröberg, Chromium-extensions
Hi Oscar, you missed an "s". It should be:
chrome.contextMenus.create( .... )

-
Mohamed Mansour
m...@chromium.org



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


Oscar Fröberg

unread,
Aug 6, 2010, 4:22:48 AM8/6/10
to Chromium-extensions
Thanks Mohamed and Arne (for responding in private)!

Arne wrote:

"Also, the onClick argument needs to be a function, so you'd have to
wrap the tab creation in an inline function or move it out into a
named function somewhere."

With your tips I got it to work, thanks again! Here's the
background.html:

<script>

function opennewtab() {
chrome.tabs.create({url: "http://www.google.com"})
}

chrome.contextMenus.create({"title": "Take me back to Google!",
contexts:["all"], "onclick": opennewtab});

</script>

On Aug 6, 6:16 am, Mohamed Mansour <m0.interact...@gmail.com> wrote:
> Hi Oscar, you missed an "s". It should be:
>
>
>
> > chrome.contextMenus.create( .... )
>
> -
> Mohamed Mansour
> m...@chromium.org
>
> On Thu, Aug 5, 2010 at 5:00 AM, Oscar Fröberg <oscarfrob...@gmail.com>wrote:
>
>
>
> > This should be pretty straightforward but whatever I try I can't get a
> > right click menu option too show. What am I doing wrong?
>
> > Chrome version 6.0.472.14 dev (Windows XP)
>
> > manifest.json
>
> > {
> >  "name": "My First Extension",
> >  "version": "1.0",
> >  "description": "The first extension that I made.",
> >  "browser_action": {
> >    "default_icon": "icon.png"
> >  },
> >  "background_page": "background.html",
> >  "permissions": [
> >    "contextMenus","tabs"
> >  ]
> > }
>
> > background.html
>
> > var url = "http://www.google.com";
>
> > chrome.contextMenu.create({"title": "Clickmeplz", "onclick":
> > chrome.tabs.create({"goooogle": url})});
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > 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<chromium-extensions%2Bunsubscr...@chromium.org>
> > .

Oscar Fröberg

unread,
Aug 6, 2010, 4:47:08 AM8/6/10
to Chromium-extensions
Next question. :) How do I get the URL of the item being right-
clicked? For instance if I want create a function that opens an image
in a new tab:

function openimageinnewtab() {
chrome.tabs.create({url: HOWDOIGETTHECORRECTURLHERE?})
}

chrome.contextMenus.create({title: "Open this image in a new tab",
contexts:["image"], onclick: openimageinnewtab});

I'm a programming noob so all help is very much appreciated!

Oscar Fröberg

unread,
Aug 6, 2010, 5:33:00 AM8/6/10
to Chromium-extensions
OMG I did it and I feel like such a genius lol!

I found the solution here: http://dev.chromium.org/developers/design-documents/extensions/context-menu-api

<script>

function openimage(info)
{
var imageurl = info.srcUrl;
chrome.tabs.create({url: imageurl})
}

chrome.contextMenus.create({title: "Open image in new tab", contexts:
["image"], onclick: openimage});

</script>
Message has been deleted

PhistucK

unread,
Aug 6, 2010, 6:46:25 AM8/6/10
to Oscar Fröberg, Chromium-extensions
You should add a property to the manifest to reflect the minimum version for which this extension is suited.

"minimum_chrome_version": "versionString",

If they made the gallery smart enough, it should not let earlier Chrome versions even install it. But I am not sure they made it so.

☆PhistucK


On Fri, Aug 6, 2010 at 13:10, Oscar Fröberg <oscarf...@gmail.com> wrote:
Here's the final result: https://chrome.google.com/extensions/detail/hgmpmjpekinnebjgnakcahjikbomnmlb

Thanks a million for the help! <3
--
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.

Arne Roomann-Kurrik

unread,
Aug 6, 2010, 2:02:52 PM8/6/10
to PhistucK, Oscar Fröberg, Chromium-extensions
I don't think the gallery has that kind of logic in it, so using this tag would be appropriate.  I believe contextMenus was taken out of experimental for Chrome 6, so the minimum version to use is 6.0.472.14 (you might be able to use 6.0.0.0 as well).

Glad you were able to work things out - sorry for responding directly earlier, I meant to reply all.

~Arne

Oscar Fröberg

unread,
Aug 6, 2010, 9:07:45 AM8/6/10
to Chromium-extensions
You're right. I noticed that the extension unfortunately only works on
the dev builds, I updated it to check for version (6+).

How do I know when it's ready for the general public? Where can I see
which functions are "stable"?

On Aug 6, 1:46 pm, PhistucK <phist...@gmail.com> wrote:
> You should add a property to the manifest to reflect the minimum version for
> which this extension is suited.
>
> "minimum_chrome_version
> <http://code.google.com/chrome/extensions/manifest.html#minimum_chrome...>":
> "*versionString*",
>
> If they made the gallery smart enough, it should not let earlier Chrome
> versions even install it. But I am not sure they made it so.
>
> ☆PhistucK
>
>
>
> On Fri, Aug 6, 2010 at 13:10, Oscar Fröberg <oscarfrob...@gmail.com> wrote:
> > Here's the final result:
> >https://chrome.google.com/extensions/detail/hgmpmjpekinnebjgnakcahjik...
>
> > Thanks a million for the help! <3
>
> > On Aug 5, 12:00 pm, Oscar Fröberg <oscarfrob...@gmail.com> wrote:
> > > This should be pretty straightforward but whatever I try I can't get a
> > > right click menu option too show. What am I doing wrong?
>
> > > Chrome version 6.0.472.14 dev (Windows XP)
>
> > > manifest.json
>
> > > {
> > >   "name": "My First Extension",
> > >   "version": "1.0",
> > >   "description": "The first extension that I made.",
> > >   "browser_action": {
> > >     "default_icon": "icon.png"
> > >   },
> > >   "background_page": "background.html",
> > >   "permissions": [
> > >     "contextMenus","tabs"
> > >   ]
>
> > > }
>
> > > background.html
>
> > > var url = "http://www.google.com";
>
> > > chrome.contextMenu.create({"title": "Clickmeplz", "onclick":
> > > chrome.tabs.create({"goooogle": url})});
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > 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<chromium-extensions%2Bunsubscr...@chromium.org>
> > .

Arne Roomann-Kurrik

unread,
Aug 6, 2010, 2:45:35 PM8/6/10
to Oscar Fröberg, Chromium-extensions
You can check what version is deployed to which channel here: http://omahaproxy.appspot.com/

We're trying to think of ways that the documentation can make it more clear as to which version any given feature is available on - currently we actually have three sets of documentation which update as new versions of Chrome are deployed to different channels.  For example,

This works:

The following don't work yet:

So the documentation for the appropriate channel will be updated as that channel gets updated to a new version.

~Arne

To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Mohamed Mansour

unread,
Aug 6, 2010, 7:05:36 PM8/6/10
to kur...@chromium.org, Oscar Fröberg, Chromium-extensions
I have a minor question. If the users of my extension have installed "ExtensionA" while they are on stable channel. Then I go and add contextMenus support with the minimum_chrome_version manifest variable and push that in the extension gallery. What happens for users on the stable channel when it requests for an update? Does an error occur, or it doesn't update? And once they reach that version, do extension developers assume that the people who were on stable that had an extension would update.

I guess the best idea right now is not to use any non-stable extension. But I was hoping there were some alternatives :
  • Experimental feature stays until it gets into stable channel.
  • OR Allow fragmentation for the extension developer. The extension developer could have some exposed variable stating what channel version, and can be responsible doing different code paths for adding experimental (or graduates) features. if (channel == DEV) initializeContextMenus().
  • OR Allow developer to upload different versions of the extension under the same name, so that transitions become easier.

-
Mohamed Mansour
m...@chromium.org

Rajiv Makhijani

unread,
Aug 6, 2010, 7:19:40 PM8/6/10
to Mohamed Mansour, kur...@chromium.org, Oscar Fröberg, Chromium-extensions
If chromium did not reject extensions with invalid permissions from being installed (i.e. such as "contextMenus," or provided a way for developers to specify which permissions were optional, then it would be more possible for extensions to rely on feature detection (as is encouraged for standard web development). Also a problem is that experimental APIs such as infobars still exist when the browser is not launched with the experimental flag, but when actually called upon, they throw permission errors.

Daniel Kantor

unread,
Aug 8, 2010, 9:04:34 PM8/8/10
to Rajiv Makhijani, Mohamed Mansour, kur...@chromium.org, Oscar Fröberg, Chromium-extensions
Has anyone tried different types? 'separator' does not seem to be working the way I would expect it. I am not seeing it show up at all on Mac 6.0.472.25. Have not tried it on Windows. A separator is drawn under a 'radio' type every time though. 

Also, the 'checkbox' and 'radio' types when in the false state do not have any UI indication that they are these types. The true state has a check next to them (for both checkbox and radio) but the false state does not have anything (an empty checkbox or radio circle)

Dan

Antony Sargent

unread,
Aug 9, 2010, 5:40:19 PM8/9/10
to Mohamed Mansour, kur...@chromium.org, Oscar Fröberg, Chromium-extensions
The extension update system *should* see that the new version of the extension requires a newer version of chrome and not install it. Please file a bug and CC me if you find that's not the case.


On Fri, Aug 6, 2010 at 4:05 PM, Mohamed Mansour <m0.inte...@gmail.com> wrote:

Antony Sargent

unread,
Aug 9, 2010, 6:03:38 PM8/9/10
to Daniel Kantor, Rajiv Makhijani, Mohamed Mansour, kur...@chromium.org, Oscar Fröberg, Chromium-extensions
For type=separator, you are running into crbug.com/49730 which I fixed last week and should show up in new builds soon.

It looks like on Mac we have a platform bug where radio type items are shown with a check instead of a circle - I'll file a bug for that (this works correctly on Windows and Linux though). 

As for not showing an indication of type when the checked state is false, our code just uses a native widget and it looks like there are different conventions on each platform (linux for instance seems to show an empty circle for radio items that aren't selected, but windows doesn't).

Daniel Kantor

unread,
Aug 9, 2010, 7:03:03 PM8/9/10
to Antony Sargent, Rajiv Makhijani, Mohamed Mansour, kur...@chromium.org, Oscar Fröberg, Chromium-extensions
Thanks for the updates. Looking forward to the new build. 
Reply all
Reply to author
Forward
0 new messages