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

386
Views
¿Hay alguna forma de obtener una variable de otro script?

Creé una extensión de Chrome, la extensión necesita obtener una variable de un script para usarla en otro contexto, puedo acceder a la variable usando la consola del navegador pero no puedo acceder a ella por mi extensión usando window.VARIABLE_NAME

 const getCodeBtn= document.getElementById('get-code-btn'); async function getCode() { let [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); chrome.scripting.executeScript({ target: { tabId: tab.id }, function: addCode, }) } //we need to add code in a website input function addCode() { const input = document.getElementById('some-id'); const btn = document.getElementById('some-id'); input.value = window.code; //window.code is undefined console.log(window.code) // undefined btn.click(); } getCodeBtn.addEventListener('click', getCode)

Todavía puedo acceder al valor de la variable en la consola del navegador

 code; // 1235469
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Según la documentación , desde Chrome 95+ puede elegir el entorno de ejecución para ejecutar el script con el parámetro world . Entonces, para ejecutarse en el entorno de la página web, su inyección debería ser algo como:

 chrome.scripting.executeScript({ target: { tabId: tab.id }, func: addCode, world: 'MAIN' })
about 4 years ago · Juan Pablo Isaza Report
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!