Search code examples
javascriptgoogle-chromeconsolegoogle-chrome-extensioncontextmenu

Google Chrome Context Menu: How use it? How or were view javascript console?


I'm trying to learn Chrome extensions. My problem is that I can't able use context menus. Nothing appears in the context menu. And how do I see the JavaScript console? I see nothing even there.

JavaScript code:

var arr_context = ["all", "page", "frame", "selection", "link", "editable", "image", "video", "audio"];
for(i=0; i<arr_context.length; i++){
    var title = arr_context[i];
    var menu1 = chrome.contextMenus.create({"type":"normal", "title":"Menu " + title, "contexts":arr_context, "onclick":callBack });
}

function callBack(info, tab){ console.log(info.menuItemId + "; URL: " + tab.url); }
/////////// NOTHING CONSOLE LOG ISSUE ///////////////////

Manifest:

{
    "name": "First Extension",
    "version": "1.0",
    "description": "The first extensione tha I made",
    "permission":["contextMenus"],
    "background_page": "background_page.html",
    "browser_action":{
                        "name": "My First Extension!",
                        "default_icon": "Chrome_icon32bn.png",
                        /* "default_popup": "popup.html", */
                        "default_title": "My First Extension!"
    },
    "icons": {
                "16": "Chrome_icon19color.png",
                "48": "Chrome_icon32color.png",
                "128": "Chrome_icon.png"
    }
}

Partly resolved: It was an error in file manifest.json. I wrote "permission" rather than "permissions".

But the second question remains. Why don't I see any console.log issue?


Solution

  • In reply to why your console.log doesn't show, I had a similar problem (and I only just started Chrome Extension development today, so that's no surprise!), for me it was solved by going to the Extensions page, and clicking on the link "_generated_background_page.html" listed under my extension.

    As I hadn't made my own background HTML page, one is generated by Chrome automatically.
    You must inspect this page for your console logs to be seen.