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

203
Views
El menú contextual no funciona a menos que tenga abiertas las extensiones devtools

Estoy tratando de hacer una extensión de Chrome que te permita agregar un texto resaltado en el DOM de la extensión usando el menú contextual. Este fragmento de código funciona bien, pero solo cuando tengo abiertas las herramientas de desarrollo para inspeccionar la extensión. De lo contrario, el comando del menú contextual no hace nada. Cualquier ayuda será apreciada, gracias.

Código JavaScript:

 if (typeof (document) !== "undefined"){ let wordList = [] const ulEl = document.getElementById("ul-el") const CONTEXT_MENU_ID = "MY_CONTEXT_MENU" const localStorageStuff = JSON.parse(localStorage.getItem("text")) if (localStorageStuff){ wordList = localStorageStuff console.log(wordList) render(wordList) } function render(words) { let renderWords = "" for (let i=0; i<words.length; i++) { renderWords += ` <li> <a target='blank_' href='http://www.google.com/search?q=${words[i]}'> ${words[i]} </a> </li> ` } ulEl.innerHTML = renderWords } function getword(info) { if (info.menuItemId !== CONTEXT_MENU_ID) { return; } console.log("Word " + info.selectionText + " was clicked.") wordList.push(info.selectionText) console.log(wordList) localStorage.setItem("text", JSON.stringify(wordList)) render(wordList) } chrome.contextMenus.removeAll(function() {chrome.contextMenus.create({ title: "Add log: %s", contexts:["selection"], id: CONTEXT_MENU_ID })}) chrome.contextMenus.onClicked.addListener(getword) }

manifiesto.json

 { "name": "Memos", "version": "1.0", "manifest_version": 3, "action": { "default_popup": "index.html" }, "permissions": [ "contextMenus", "tabs", "storage" ], "background": { "service_worker": "index.js" } }
about 4 years ago · Juan Pablo Isaza
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!