0

I want to make a chrome extension where I can use key commands on specific pages (Eg: "Ctrl+Shift+A") which then triggers some DOM manipulation code (such as clicking a button).

But the issue I am facing is that "chrome.commands" runs in the background environment (background property in manifest.json) and If I include "chrome.commands.onCommand" in content_scripts (inside manifest.json) I get this error.

Uncaught TypeError: Cannot read property 'onCommand' of undefined.

How do I make it work?

codezart
  • 67
  • 4

1 Answers1

1

Use two scripts. The background script registers a chrome.commands listener which injects a content script (or sends a message to a content script declared in manifest.json). The content script runs in the web page and has access to its DOM.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136