Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
Chrome Extension open popup by command

I want to use a shortcut Ctrl + B to open popup.html of my extension, so I don't need to move the mouse and click.

I tried the commands config from Google document but it seems doesn't work. Does anyone know how to fix this? Below is my configuration (Note that I'm using manifest_version: 3)

manifest.json:

{
  "name": "",
  "description": "",
  "version": "0.0.1",
  "manifest_version": 3,
  "background": {
    "service_worker": "background.js"
  },
  "action": {
    "default_popup": "popup.html"
  },
"commands": {
    "_execute_action": {
      "suggested_key": {
        "default": "Ctrl+B",
        "mac": "Ctrl+B"
      }
    }
  }
}

popup.html

<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  Hello world
</body>
</html>

background.js

// Currently empty
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Don't know if this works for you, but if position of popup.html is not an issue for you this shall work if added to your background.js script. (executed on local host in manifest version 3)

manifest.json

 "commands": {
 "my_shortcut": {
  "suggested_key": {
    "default": "Ctrl+B",
    "mac": "Command+B"
  },
  "description": "Opens popup.html",
  "global": true
},
}

background.js

chrome.commands.onCommand.addListener((command) => {

if (command === 'my_shortcut')
    chrome.system.display.getInfo({ singleUnified: true }, (info) => {
    
      const wDimension = info[0].workArea;
      const { top, left, height, width } = wDimension;
      console.log(top);
      const w = 440;
      const h = 220;
      const l = width / 2 - w / 2 + left;
      const t = height / 2 - h / 2 + top;
      const newWindow = () => {
        console.log('in new window function');
      };
      chrome.windows.create(
        {
          url: 'popup.html',
          type: 'popup',
          width: w,
          height: h,
          left: Math.round(l),
          top: Math.round(t),
        },
        newWindow
      );
    });
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda