Is there a way to access the Chrome Extension popup using a keyboard shortcut?

While it is not possible to directly open a Chrome extension popup from background JavaScript, is there a method where the popup could be triggered when a user presses a specific key combination?

Answer №1

The chrome.commands API allows users to set up hotkeys for executing specific commands, like opening the browser action.

For example, you can visit this GitHub repository to see how pressing Ctrl+Shift+F on Windows (Command+Shift+F on a Mac) will open the browser action popup, or pressing Ctrl+Shift+Y will trigger an event (Command+Shift+Y on a Mac).

Answer №2

If your manifest_version is set to 3, your manifest.json should resemble the following in order to open a popup using a keyboard shortcut:

What's happening here is that the keyboard shortcut is linked to _execute_action, which then triggers the default action of opening the popup.

{
    "manifest_version": 3,
    "name": "Search Hindi Website",
    "version": "1.0",
    "description": "Search a Hindi website using English text",
    "icons": {
        "16": "icon16.png",
        "32": "icon32.png",
        "48": "icon48.png",
        "128": "icon128.png"
    },
    "permissions": ["scripting", "activeTab"],
    "action": {
        "default_popup": "popup.html",
        "default_icon": {
            "16": "icon16.png",
            "32": "icon32.png",
            "48": "icon48.png",
            "128": "icon128.png"
        }
    },
    "background": {
        "service_worker": "background.js"
    },
    "content_scripts": [
        {
            "matches": ["https://*/*"],
            "css": ["mark.css"]
        }
    ],
    "commands": {
        "_execute_action": {
            "suggested_key": {
                "default": "Alt+Shift+P",
                "mac": "MacCtrl+Command+P"
            }
        }
    }
}

A similar setup for manifest_version 2 will appear as follows:

{
    "manifest_version": 3,
    "name": "Search Hindi Website",
    "version": "1.0",
    "description": "Search a Hindi website using English text",
    "icons": {
        "16": "icon16.png",
        "32": "icon32.png",
        "48": "icon48.png",
        "128": "icon128.png"
    },
    "permissions": ["scripting", "activeTab"],
    "browser_action": {
        "default_popup": "popup.html",
        "default_icon": {
            "16": "icon16.png",
            "32": "icon32.png",
            "48": "icon48.png",
            "128": "icon128.png"
        }
    },
    "background": {
        "service_worker": "background.js"
    },
    "content_scripts": [
        {
            "matches": ["https://*/*"],
            "css": ["mark.css"]
        }
    ],
    "commands": {
         "_execute_browser_action": {
            "suggested_key": {
                "default": "Alt+Shift+E",
                "mac": "MacCtrl+Command+E"
            }
        },
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript: Populating an Array with Image URLs Using a Loop

My image gallery project has hit a roadblock and my JavaScript skills are not up to par. Maybe it's time to brush up on the basics with a good book from the library. Here's what I want to achieve: 1. Create an array of URL's for each imag ...

no such file exists in the directory

My current project involves connecting a javascript file to an html file using the <script> tag. However, upon rendering the html page, I encountered an error in the console indicating that the javascript file could not be located. Here is the struc ...

Export data from a JSON object to a CSV file within the Osmosis function

I am currently utilizing Osmosis, a node.js tool, to extract data in the form of an array of JSON objects. The behavior of Osmosis functions indicates that the array is confined within the function's scope. Consequently, I must also write the file in ...

What is the best way to continuously monitor MongoDB for updates and sync them with my user interface?

Looking to continuously monitor a user's notifications in MongoDB, updating them on specific actions and displaying updates on my React frontend without reloading every time the user logs in. I am currently utilizing Node and Mongoose models for datab ...

What would be the most effective approach for creating a reactive setter for an object within an array in Vuex?

I am working with a Vuex object that contains an array of languages consisting of objects with guid, name, and level properties. I am trying to figure out how to write a method that will make it reactive. Currently, I have an input field with a value of " ...

Transfer a photo from your computer's storage and seamlessly add it to your text message

I'm looking to implement a functionality similar to the "ask question" page on StackOverflow. My goal is to have a textarea for entering a message and an "Add image" button above it. When the button is clicked, a dialog appears with an option to "Choo ...

What is the best way to dynamically generate a component and provide props to it programmatically?

I am interested in creating a function that can return a component with specific props assigned to it. Something like a reusable component for Text/View/Pressable, where styles can be extracted and passed as props. Personally, I find it more efficient to s ...

Steer clear of chaining multiple subscriptions in RXJS to improve code

I have some code that I am trying to optimize: someService.subscribeToChanges().subscribe(value => { const newValue = someArray.find(val => val.id === value.id) if (newValue) { if (value.status === 'someStatus') { ...

An issue with the Babel version is preventing the Express API from starting up successfully

Error! Message: [nodemon] starting `babel-node index.js` C:\Users\Zara Gunner\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-ma ...

Using jQuery, eliminate a single value from all drop down options

I am facing an issue where I have multiple drop-downs with the same values. When a user selects "Lunch" from one of the drop-downs, I need to remove "Lunch" from the rest. Below is my code: Frontend code: <?php for($i=1; $i<=7; $i++) {?> <se ...

I'm having trouble getting my JavaScript code to run, can anyone offer any advice on what

Can you provide assistance with this code? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=" ...

Tips for establishing and connecting numerous connections among current nodes using the same criteria

While browsing StackOverflow, I came across similar questions. However, I believe this one has a unique twist. The main issue at hand is: How can I establish multiple relationships between existing nodes? I have the following code snippet: session . ...

Positioning Arrows Adjacent to Definitions

I have a PHP snippet that adds arrow indicators next to previous and next sections on a page. This allows users to easily navigate between sections by clicking on the arrows. The desired output format is: (arrow) Previous Section Next Section ...

I'm experiencing difficulties with a JavaScript slideshow in Vegas

After installing the vegas jQuery plugin to my project using npm, I encountered issues when attempting to use it according to the documentation. Despite linking the required vegas.min.js and vegas.min.css files in my HTML, the plugin doesn't appear to ...

JavaScript multi-click navigation menu

I'm relatively new to JavaScript and I've been struggling with using multiple onClick attributes. While I have some code that works, I feel like there might be a simpler and cleaner solution to my problem. What I'm trying to achieve is a na ...

What is the best method to detect a change in scroll position on a webpage using JavaScript?

Is there a way to trigger an event when the page's scroll position changes? I'm interested in creating a dynamic table of contents similar to (where the active item changes as you scroll). Can this be achieved without directly accessing the cu ...

What is the functionality of ng-repeat in AngularJS when used outside the "jump" table?

Currently, I am in the process of constructing a layout using a table with nested ng-repeat. <div ng-controller="PresetManageController"> <table> <in-preset ng-repeat="preset in presetManage.presets"></in-preset> </table ...

The issue I am facing is with the post_logout_redirect_uri not functioning properly when using localStorage in an OIDC Auth

authority: 'yyy', client_id: this.'yyy', redirect_uri: 'http://localhost:4200/login', response_type: 'token', scope: 'yyy', post_logout_redirect_uri: & ...

Operating a slider on a web page built with HTML

I am currently working on developing a loan calculator that involves two range sliders interacting with each other to display monthly payments in a label. Here are the specific requirements: Display only 5 values on the "Month" range slider: 12,18,24,30,3 ...

Generating div elements of varying colors using a combination of Jinja templating and JavaScript loop

Utilizing jinja and javascript in my template, I am creating multiple rows of 100 boxes where the color of each box depends on the data associated with that row. For instance, if a row in my dataset looks like this: year men women 1988 60 40 The co ...