To handle the logic for our duplicate-tab command, we will need a background script. Notice that this command also includes a description, which is not required for reserved commands (chrome just displays a default description that cannot be overridden). duplicate-tab: This is a custom command that our extension must handle manually.We do not need to handle the logic for this command ourselves. By defining it in our manifest.json, we are telling chrome to open our browser action when the user executes the shortcut. _execute_browser_action: This is a reserved command that will be handled by chrome directly.In the previous code, we defined 2 different commands: To define a command, we should use the commands property in our manifest.json file, like so:Įnter fullscreen mode Exit fullscreen mode Define the commands in the manifest.json file We should handle the logic that we want to execute once the user runs a command in a background script. Keep in mind that you cannot use commands reserved by the browser, like Ctrl + T (which in Chrome opens a new tab). Other supported keys: A-Z, 0-9, Comma, Period, Home, End, PageUp, PageDown, Space, Insert, Delete, Arrow keys ( Up, Down, Left, Right) and the Media Keys ( MediaNextTrack, MediaPlayPause, MediaPrevTrack, MediaStop).Įxamples: Ctrl + Shift + L, Alt + Shift + L Command +, Ctrl + Shift + 1 The user can bind the other commands to a keyboard shortcut from the browser ( chrome://extensions/shortcuts).Īny keyboard shortcut must use either Ctrl ( Command in Mac) or Alt but cannot include both. However, only 4 shortcuts can be suggested by our extension. We can define multiple commands in the manifest.json. We must declare our commands in the manifest.json file along with their suggested keyboard shortcut. When someone uses the shortcut, the command will be triggered, and the appropriate logic will be executed. Through this API, we can define commands and bind them to a combination of keys. To create a keyboard shortcut for our extension, we must use the commands API. Ctrl/Command + Shift + 2 will duplicate the current tab.Alt + Shift + 1 will open our browser action.Today we are going to work on a new feature: Keyboard shortcuts. Last week I wrote an article explaining how to create a simple chrome extension.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |