Chrome extension : context menu not working properly.

1,971 views
Skip to first unread message

dhi...@nadsoftdev.com

unread,
Aug 27, 2013, 6:29:24 AM8/27/13
to chromium-...@chromium.org
HI ,


I am trying to add context menu in extension.
Sometimes it work , sometimes not can you tell me what is the issue & what will be the possible solution.
Context menu work properly when I inspect popup for the extension otherwise not.

here is the code :

chrome.contextMenus.removeAll();

var contexts=["selection"];

var context = contexts[0];

var title = "Phone Dial";

var id = chrome.contextMenus.create({"title": title, "contexts":[context]},function (){ 

var child1  = chrome.contextMenus.create({"title": "call", "contexts":[context], "parentId": id, "onclick": CallNumber});

});



Adrian Aichner

unread,
Aug 27, 2013, 6:40:06 AM8/27/13
to Chromium-extensions


---------- Forwarded message ----------
From: Adrian Aichner <adrian....@gmail.com>
Date: Tue, Aug 27, 2013 at 12:36 PM
Subject: Re: [crx] Chrome extension : context menu not working properly.
To: dhi...@nadsoftdev.com


Open the background page for your extension from chrome:extensions.
Switch to Console there and you will probably see errors like in following comment and workaround.

// TODO Please note this removeAll is necessary to avoid following warning when extension is reloaded:
// contextMenus.create: Cannot create item with duplicate id ID
chrome.contextMenus.removeAll(function() {
if (chrome.extension.lastError) {
console.log("lastError:" + chrome.extension.lastError.message);
}
});

One way to avoid the duplicate IDs is this:
        var removeAllAutsosavesId = chrome.contextMenus.create({
            id: "removeAllAutosaves" + Date.now(),

I have not found information about the best established practice yet.

Anyone?




--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/c8e25933-368d-4915-a593-1c53baa1693d%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/groups/opt_out.


dhi...@nadsoftdev.com

unread,
Aug 27, 2013, 6:47:58 AM8/27/13
to chromium-...@chromium.org
it does not show any error on console. 


Adrian Aichner

unread,
Aug 27, 2013, 8:18:01 AM8/27/13
to dhi...@nadsoftdev.com, Chromium-extensions
Are you sure you look at the backgound page JS console?

What does
location.href
give you?

Should be something like


or your hand-crafted background.html, if you declared one.


On Tue, Aug 27, 2013 at 12:47 PM, <dhi...@nadsoftdev.com> wrote:
it does not show any error on console. 


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Adrian Aichner

unread,
Aug 27, 2013, 8:21:26 AM8/27/13
to dhi...@nadsoftdev.com, Chromium-extensions
Also, make sure all log sources are checked in the devtools filter icon Y and (All) in selected, as opposed to only (Error), (Warnigns), (Logs), or (Debug).

Adrian Aichner

unread,
Aug 27, 2013, 8:50:22 AM8/27/13
to Dhiraj Rode, Chromium-extensions
What does the Permissions link for that extension in chrome://extensions/ have to say?

Does popup.html load the .js file which executes the create method?

Does the manifest.json have the "contextMenus" permission?

What do you have in "background": {
    "scripts": ["???.js"]
  }

That's where the menu should be created, AFAIK.



On Tue, Aug 27, 2013 at 2:42 PM, Dhiraj Rode <dhi...@nadsoftdev.com> wrote:
yes,
i am sure , its giving url as : 


and (all) option is selected for the errors also all the options are checked under Y option.


--
Thank you,
Dhiraj Rode
9665879483


Adrian Aichner

unread,
Aug 27, 2013, 9:19:46 AM8/27/13
to Dhiraj Rode, Chromium-extensions
Please don't drop the google group in your replies (use Reply to All)

You should only see the context menu when you have made a text selection in a webpage which loaded your extension succesfully.

Were you selecting some text first in your experiments?


On Tue, Aug 27, 2013 at 3:04 PM, Dhiraj Rode <dhi...@nadsoftdev.com> wrote:
Yes ,

manifest.json have permission have "contextMenus".

I have added the contextmenu.js file which i used to add context menu functionality in bg-page.html page & added bg-page.html page as :

"background"      : {
     "page": "bg-page.html"
 } 

also contextMenu.js is loaded successfully .

Dhiraj Rode

unread,
Aug 27, 2013, 9:27:09 AM8/27/13
to Adrian Aichner, Chromium-extensions
Yes, 
Firstly I need to select text then only the extension context menu will appear.
Right now, my extension works properly instead of the context menu functionality.
If I inspect the popup.html page then the context Menu functionality also work properly otherwise didn't work   

Adrian Aichner

unread,
Aug 27, 2013, 10:00:28 AM8/27/13
to Dhiraj Rode, Chromium-extensions
Load contextMenu.js into bg-page.html instead. That will make it work, since the background page always gets loaded.

Dhiraj Nadsoft

unread,
Aug 27, 2013, 10:34:59 AM8/27/13
to Adrian Aichner, Chromium-extensions
It's already in bg-page.html 


Reply all
Reply to author
Forward
0 new messages