Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
chrome.scripting.executeScript pass parameter

I have this code in the popup.js file on my Chrome Extension:

chrome.scripting.executeScript({
  target: { tabId: tab.id },
  function: myFunc,
});


function myFunc() {
  // do something
}

However, I would like to pass a parameter from the executeScript to myFunc. Something like this:

chrome.scripting.executeScript({
  argument: {"arg1", "arg2"}
  target: { tabId: tab.id },
  function: connectCmd,
});


function myFunc(arg1: string, arg2: string) {
  // do something
}

or something equivalent. Is there any way to do this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Per the documentation the args (array of arguments) property is available since Chrome 92.

  • These arguments must be JSON-serializable i.e. string, number, boolean, null, array/object that consists of the mentioned types. In short the injected code will see the same thing as you can see by running JSON.parse(JSON.stringify(args)) meaning that you can't transfer classes, Set, Map, and other nontrivial objects.
  • You can use func property in Chrome 92+, which is the new preferred alias of function.
chrome.scripting.executeScript({
  args: ['foo', 'bar']
  target: { tabId: tab.id },
  func: myFunc,
});

function myFunc(arg1, arg2) {
  console.log(arg1, arg2); // will print `foo bar` in console of the web page
}

In the older Chrome you'll have to use messaging.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda