Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!