Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

340
Visualizações
Using Chrome Extension Manifest V3, How Do I Execute Code Strings?

I’m writing a Chrome extension using Manifest V3 and trying to find a way to execute code strings dynamically (similar to userscripts). There are methods to execute code strings (eval, setTimeout, new Function, etc.); however, they seem forbidden in Manifest V3. While setTimeout still works, the Chrome team states that executing code strings will no longer be accepted when submitted to the Chrome Web Store. The code needs to be part of the extension when submitted. Also stated in the link below under “Remotely Hosted Code”:

https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/

Saw some forum posts and crbugs posted about this issue, but they all seem outdated without a definitive answer. Like the link above, older posts state that it will no longer be possible to execute code strings. Newer but still outdated (2020) posts state that Manifest V3 will have use cases (such as TamperMonkey) where userscripts can be registered dynamically but only after giving the user a prompt. The only two methods I see that let an extension run scripts dynamically are “chrome.scripting.registerContentScripts” and “chrome.scripting.executeScript”. Both methods execute code from files, not strings. The older method “chrome.tabs.executeScript” used to allow executing code strings but is now deprecated.

Is there a way that is allowed by the Chrome Web Store or any update to this issue?

Edit 1:

If executing scripts dynamically from files is the only way:

  1. Do Chrome Extensions allow saving files in the extension directory? Or would it invalidate the extension (the extension is automatically uninstalled because of some security policy)?
  2. If the extension is allowed to save files outside of the extension directory, can the two current methods (mentioned above) execute those files?

Edit 2:

Reworded 2 (under Edit 1).

Edit 3:

Thanks to all that have replied. Doesn’t seem like there is a solution to this issue, yet. There have been no public announcements that I have heard or read about as to how (if it’s possible) script code strings can be dynamically executed (that would not be rejected by the Chrome Web Store).

As of November 13, 2021, you can do one of the following:

  • Depending on your use case, take the advice from @wOxxOm or @hashed tomato.
  • Downgrade to Manifest V2 and use “chrome.tabs.executeScript”. This is only a temporary fix as Manifest V2 will cease to work after a specified time.
  • Not sure if this will be rejected when submitting the extension to the CWS. Allow the user to save scripts via the extension. As of the time I’m writing this, I don’t know of a way to save the files that will enable the saved files to be executed by one of the other two methods “chrome.scripting.registerContentScripts” and “chrome.scripting.executeScript”. Testing needs to be done, otherwise, I would state it here.

Thanks everyone.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In sandbox, code string can be executed.

https://developer.chrome.com/docs/extensions/mv3/manifest/sandbox/

There is several restrictions to the sandbox code, for example, it cannot access to DOM. It depends on what you want to do by the code string.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda