chrome.browserAction.onClicked.addListener(function(){ var objList = document.getElementsByClassName("anyClass"); alert(objList.length) }) By clicking on the extension icon, an alert should be displayed showing the number of elements on the page with the class. But it always returns 0. If you register in the console
var objList = document.getElementsByClassName("anyClass") That list is created. If through expansion then no. What am I doing wrong?