Commands not executing from extension

220 views
Skip to first unread message

Marc Selwan

unread,
Feb 11, 2014, 10:05:20 AM2/11/14
to chromium-...@chromium.org
Hello friends, 

I'm having a little trouble getting "commands" to work. Nothing seems to be happening when I execute the commands - maybe i'm overlooking something. Here is my manifest + background.js 

{

    

    "manifest_version": 2,

    

    "name": "my extension",

    

    "description": "Search the KB - More features coming soon",

    

    "version": "1.4",

    

    "permissions": [

                    

                    "tabs",

                    

                    "http://*/*",

                    

                    "https://*/*"

                    

                    ],


    "commands": {

        "open-site": {

            "suggested_key": {

                "windows": "Ctrl+Shift+P",

                "mac": "Command+Shift+P"

            },

            "description": "Opens site"

        }

        

    },

    

    "browser_action": {

        

        "default_title": "Search the KB!",

        

        "default_icon": "icon.png",

        

        "default_popup": "popup.html"

        

    },

    

    "background": {

        

        "scripts": ["background.js"]

        

    }

    


    

}



background.js: 


//document.addEventListener("click", searchThis, false);

//document.addEventListener("click",gotoKB, false);


var d = new Date();

var dateNumber = d.getDay();

var t = new Date();

var hoursLogout = t.getHours();

var m = new Date();

var minutesLogout = m.getMinutes();


var logoutTime = hoursLogout+minutesLogout


chrome.commands.onCommand.addListener(function(command) {

                                      if (command === 'open-site') {

                                      console.log("We did it!");

                                      chrome.tabs.create({'url': "mywebsite"});

                                      }

                                      });



//opens the KB and searches using keyword from popup.html form

function searchThis() {


    var search = document.getElementById("searchID")

    chrome.tabs.create({'url': "website" + search.value});

    


    

}

//simply opens the KB 

function gotoKB() {

    

    chrome.tabs.create({'url': "website"});

    


}


//Makes Chrome remind you to do your timecard on Fridays every 4 hours 

if (!document.cookie.match(/(?:^|; *)alert_timecard=1/) && dateNumber == 5) {

    

    alert("Don't forget your timecards :)");

    document.cookie = "alert_timecard=1;max-age=" + 60 * 60 * 4;

};


//Makes Chrome 

if (!document.cookie.match(/(?:^|; *)alert_logout=1/) && logoutTime == 72) {

    

    alert("Don't forget to logout!");

    document.cookie = "alert_logout=1;max-age=" + 60 * 60 * 1;

};



//initializign listeners

var searchBtn = document.getElementById("searchBtn");

var kbBTN = document.getElementById("kbBtn");

searchBtn.addEventListener("click",searchThis,false);

kbBTN.addEventListener("click",gotoKB,false);




Thanks in advanced for any help. Right now, nothing shows in the console either. 

Finnur Thorarinsson

unread,
Feb 11, 2014, 11:03:54 AM2/11/14
to Marc Selwan, Chromium-extensions
 Right now, nothing shows in the console either. 

Are you inspecting the background page (of your extension) for errors via chrome://extensions (and not the current page you are on)?

Because I see an error at the bottom of the script:

var searchBtn = document.getElementById("searchBtn");

... searchBtn is null so adding an event listener to it is not going to work.

Also check chrome://extensions \ Keyboard Shortcuts to see what shortcut your action got assigned upon install. If the manifest is correctly structured and you still don't see a key then maybe you are hitting a reserved Chrome accelerator or another extension has this key assigned.




--
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/30c39550-a291-4687-b244-e10699bbd996%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/groups/opt_out.

Marc Selwan

unread,
Feb 11, 2014, 11:12:28 AM2/11/14
to chromium-...@chromium.org, Marc Selwan
Thanks for the reply Finnur, 

That's weird, I saw that error just now - The listener still works (and shouldn't be null) so I'm not sure why that's sounding off the error. I'll keep playing with it. Thanks! 
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
Reply all
Reply to author
Forward
0 new messages