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

134
Views
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 answers
Answer question

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 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!