1

I'm converting the version of manifest from 2 to 3, as we cannot use chrome.tabs.executeScript , i'm using chrome.scripting.executeScript to execute the injection

in manifest v2 I had below lines of code

chrome.tabs.executeScript(tabid, {
  code: appssoscript[0].chrome,
  runAt: 'document_start'
});

where appssoscript[0].chrome consists of value:

document.getElementById("username").value="application_user1";
document.getElementById("password").value="Passw0rd@123";
document.querySelector(".from__button--floating").click();`

in manifest v3 i've changed the code to

chrome.scripting.executeScript({ 
  target: {tabId: tabid},
  func : getScript,
  args : [appssoscript[0].chrome],
});

in above code I'm executing a function called getScript where I'm passing argument appssoscript[0].chrome but the function is not injecting values

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
Kishen RC
  • 21
  • 1
  • Please see [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Norio Yamamoto May 09 '23 at 09:05
  • Remove `args` and simply put the value's inner contents (the second block in your question) into getScript as code not as a string, see [these examples](/a/67227376). – wOxxOm May 09 '23 at 10:21
  • The script we are trying to inject here is coming dynamically, so we can't hardcode it we have to capture it from the page and then we have to pass it, please let us know how to pass the value and then inject it – Kishen RC May 09 '23 at 12:02

1 Answers1

-1

Please try this.

const getScript = (script) => {
  Function(script)();
}

chrome.scripting.executeScript({ 
  target: {tabId: tabid},
  world: "MAIN",
  func : getScript,
  args : [appssoscript[0].chrome]
});
Norio Yamamoto
  • 1,495
  • 2
  • 3
  • 10