Estoy tratando de obtener el texto seleccionado y abrir esta palabra en el sitio web del diccionario. Estoy apuntando esto seleccionando la palabra y cuando hago clic derecho, se abrirá como una nueva pestaña. Pero me estoy perdiendo algo.
Aquí está mi fondo.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 }); };Y aquí está mi 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" ] }De esta forma, podría haber seleccionado la palabra y mostrarla en el menú contextual.
Pero, ¿cómo puedo ir al sitio web que quiero?