GoogleChrome / chrome-extensions-samples

Chrome Extensions Samples
https://developer.chrome.com/docs/extensions
Apache License 2.0
15.13k stars 8.11k forks source link

Sample for chrome.commands API #1126

Open hrmtsh2 opened 5 months ago

hrmtsh2 commented 5 months ago

I would like to write a sample for chrome.commands. The idea is to have keyboard shortcuts trigger dark/light mode (through content script injection). It could have different shortcuts for different functionalities (say, one for dark mode and another for embedding reading time estimate). @oliverdunk @jpmedley kindly give suggestions or the go-ahead.

hrmtsh2 commented 5 months ago

Realised that many samples already use commands (albeit not custom commands). Closing issue

kalpanmukherjee commented 3 months ago

hi @hrmtsh2, could you point me towards any of these samples? much appreciated

hrmtsh2 commented 3 months ago

Well, coming back to this issue, I have been unable to find a single sample that explicitly uses the "command" property in the manifest (I swear I saw many when I closed the issue!). Even if there were, it was certainly small in number, and many samples do not, in fact, demonstrate the commands API. I suppose one could do this by either incorporating it into existing samples, or by creating a new (set of) api-samples for it. So I will reopen this issue.

oliverdunk commented 3 months ago

Hi @hrmtsh2, an example of an extension using the manifest declaration would be this one: https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/api-samples/default_command_override

The only thing I don't see right now is an example of an extension using the getAll method. I think a new sample demonstrating that or updating an existing sample would make sense, if you want to work on something :)

hrmtsh2 commented 3 months ago

Sorry I was unable to find this before. Yes, I will work on a sample demonstrating the getAll() method. My first idea was to extend the sample you've linked here to use getAll() in two ways:-

  1. To display all shortcuts in the extension popup (will be extending the sample you linked above with a couple more shortcuts and a popup)
  2. To check for unassigned shortcuts (this case could arise when two extensions attempt to register the same shortcuts) as is demonstrated in the docs