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

248
Visualizações
How to open a link in a new tab by using context menu?

I am trying to get selected text and open this word in dictionary web site. I am aiming this by selecting the word and when I right click, it'll be open as new tab. But I am missing something.

Here is my background.js

const BASE_URL = "http://lugatim.com/s/";

chrome.runtime.onMessage.addListener((data) => {
  if (data.type === "notification") {
    notify(data.message);
  }
});

chrome.runtime.onInstalled.addListener(() => {
  chrome.contextMenus.create({
    id: "word",
    title: "Kelimeyi ara: %s",
    contexts: ["selection"],
    onClicked: (info, tab) => {
      console.log(info);
      chrome.tabs.create({
        url: BASE_URL + encodeURIComponent(info.selectionText),
      });
    },
  });
});

chrome.contextMenus.onClicked.addListener((info, tab) => {
  if ("word" === info.menuItemId) {
    notify(info.selectionText);
    openSite(info.selectionText);
  }
});

const notify = (message) => {
  return chrome.notifications.create("", {
    type: "basic",
    title: "Notify!",
    message: message || "Notify!",
    iconUrl: "./assets/icons/128.png",
  });
};

const openSite = (word) => {
  return chrome.tabs.create({ url: BASE_URL + word });
};

And here is my manifest.json

{
  "manifest_version": 3,
  "name": "TEST",
  "description": "TEST",
  "version": "1.0.0",
  "icons": { "128": "lugatim_128.png" },
  "action": {
    "default_icon": "lugatim_19.png",
    "default_popup": "popup.html"
  },
  "content_security_policy": {
    "extension_pages": "script-src 'self'; object-src 'self'"
  },

  "background": {
    "service_worker": "background.js"
  },
  "permissions": [
    "tabs",
    "activeTab",
    "contextMenus",
    "storage",
    "activeTab",
    "notifications"
  ]
}

By this way, I could have selected the word and show it in the context menu

enter image description here

But how can I go to the website I want?

about 4 years ago · Santiago Gelvez
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