

To make a command global, we just need to add the key global to its definition in manifest.json and set it to true:Ĭhrome. In this section, we'll create a global standard command that when the user presses Ctrl+Shift+8, it will log to the console of the service worker or background script the current date. Now, try clicking the shortcut Ctrl+Shift+P and you'll see "Hello there!" logged in the console. This will open the devtools for the service worker or background script. Then, for MV3 extensions click on "Inspect views service worker"įor MV2 extensions click on "Inspect views background page" Go to chrome://extensions and refresh the extension. In manifest.json, add another command under the commands key: This section is the same for both MV3 and MV2, so you can follow along regardless of what version your extension is.

It will run as long as Chrome is in focus, regardless of what page or tab is open. The standard command we'll create will use the shortcut Ctrl+Shift+P to print to the console of the service worker or background script "Hello there!". So, if the command does not work for you, try changing the shortcut in the manifest, then refresh the extension and try again. Similarly, if the shortcut is used by the browser or your operating system, then it will not be triggered. Also, it should be noted that if other extensions that were installed previously use this shortcut, they'll have precedence to use the shortcut. If it doesn't work, make sure that Ctrl+Shift+P in your manifest.json is written correctly, as this is case-sensitive. If you keep pressing the same shortcut, it will toggle between light and dark mode. Remember that we're taking a simple approach to dark mode, so obviously it will not actually look good. Then, in an open tab (if you're creating an MV2 extension you'll need to refresh the page), press Ctrl+Shift+L, and the document's body background color will change to black and the text to white. First, go to chrome://extensions and refresh the extension. Standard commands are defined in the following format: Instead, in MV3 they trigger, and in MV2 they trigger or .Ĭommands are defined in an extension's manifest.json under the commands key. Action commands do not trigger the event. Action commands can have access to the current tab and can execute a script on the current page. Standard commands trigger the event, and you can listen to it in your background script or service worker.Īction commands map the shortcuts to your extension's action (if MV3) or browser action or page action (if MV2). A standard command runs in the background script or service worker and has no access to the current page or tab opened. A standard command and an action command. An extension can have at most 4 commands. Once done, the extension will be added to your Chrome browser.Ĭhrome commands allow an extension to register commands, or keyboard shortcuts, to provide ease of use for the users of that extension to perform certain actions through those shortcuts. Then, go to chrome://extensions/ on your Chrome browser, enable Developer Mode if you haven't from the top right, click on "Load unpacked" and choose the folder that you created for your extension.
#SHORTCUT MAC FOR SWITCHING FROM CHROME WINDOW TO CHROME WINDOW DOWNLOAD#
Also, make sure to download the icons from the GitHub repository first, or add your own icons.
