1

So I'm working on a Chrome Extension to reload a page at regular intervals but I've found an error: Error handling response: TypeError: Error in invocation of pageAction.show(integer tabId, optional function callback): No matching signature..

manifest.json:

{
  "name": "Reloader",
  "version": "1.0.0",
  "description": "Reloads pages.",
  "permissions": ["tabs", "declarativeContent", "storage"],
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "page_action": {
    "default_popup": "popup.html",
    "default_icon": {
      "16": "images/symbolsmall.png"
    }
  },
  "manifest_version": 2
}

background.js:

chrome.tabs.onActivated.addListener(function(tabs) {
    chrome.pageAction.show(tabs.id);
});

I did some console.logs and checked the docs for chrome.pageAction.show and the syntax checks out but the error persists. Any help would be much appreciated.

Kenzoid
  • 276
  • 1
  • 16

2 Answers2

3

The error message means you've passed an incorrect parameter. If you debug your code in devtools for the background page, you'll see tabs.id is undefined. As you can see in the documentation the listener of onActivated receives an object with tabId and windowId inside:

chrome.tabs.onActivated.addListener(function(activeInfo) {
  chrome.pageAction.show(activeInfo.tabId);
});

Note, if you plan on showing the page_action unconditionally like you do currently, there's no benefit in using page_action at all and you can simply switch to browser_action which is enabled by default so you won't need to show() it.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • Thanks for the suggestion with browser action, I'm new to extensions so I'm not great and your comment helped a lot, thanks! – Kenzoid Jul 24 '19 at 15:32
1

This error also occurs when you call a function in the callback parameter instead of passing it.

function foo(param){
  //do something
}


chrome.tabs.onActivated.addListener(foo(param)); //this will give you the error
chrome.tabs.onActivated.addListener(foo); //this should work fine

Seems obvious but, I have made this error countless times. Hope it is helpful.

Zhang Chandra
  • 81
  • 1
  • 6