SKG SKG - 1 year ago 116
JSON Question isn't working in tabs.onCreated listener


chrome.tabs.onCreated.addListener(function(tab) {;//Doesn't work...icon is still grey


This is part of the code from my extension. I want every new tab to show page action whenever it's created. Unfortunately,
doesn't work. Everytime I create a new tab, its icon is grayed out.

However to my surprise, if I call
from console, it works perfectly.


"name": "show Page Action",
"description": "show icon in all tabs",
"version": "1.0",
"background": {
"scripts": ["jquery-3.1.1.min.js", "background.js"]
"page_action": {
"default_icon": "icon_true.png"
"manifest_version": 2

Answer Source

pageAction API is URL-based so you need to use tabs.onUpdated, which is executed after onCreated and has different parameters:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if (changeInfo.url) {;

Don't forget to add "tabs" in manifest.json's "permissions".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download