[英]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).我正在使用 Manifest V3 编写 Chrome 扩展程序,并试图找到一种动态执行代码字符串的方法(类似于用户脚本)。 There are methods to execute code strings (eval, setTimeout, new Function, etc.);
有执行代码字符串的方法(eval、setTimeout、new Function等); however, they seem forbidden in Manifest V3.
然而,它们在 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.
虽然 setTimeout 仍然有效,但 Chrome 团队表示,当提交到 Chrome 网上应用店时,将不再接受执行代码字符串。 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/ 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.看到一些关于这个问题的论坛帖子和 crbugs 发布,但它们似乎都过时了,没有明确的答案。 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.
较新但仍然过时(2020 年)的帖子指出,Manifest V3 将具有用例(例如 TamperMonkey),其中可以动态注册用户脚本,但只能在给用户提示之后。 The only two methods I see that let an extension run scripts dynamically are “chrome.scripting.registerContentScripts” and “chrome.scripting.executeScript”.
我看到的唯一两种让扩展程序动态运行脚本的方法是“chrome.scripting.registerContentScripts”和“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.
旧方法“chrome.tabs.executeScript”曾经允许执行代码字符串,但现在已弃用。
Is there a way that is allowed by the Chrome Web Store or any update to this issue? Chrome 网上应用店或对此问题的任何更新是否有允许的方法?
Edit:编辑:
If executing scripts dynamically from files is the only way:如果从文件动态执行脚本是唯一的方法:
Thanks.谢谢。
In sandbox, code string can be executed.在沙箱中,可以执行代码字符串。
https://developer.chrome.com/docs/extensions/mv3/manifest/sandbox/ https://developer.chrome.com/docs/extensions/mv3/manifest/sandbox/
There is several restrictions to the sandbox code, for example, it cannot access to DOM.沙箱代码有几个限制,例如,它不能访问 DOM。 It depends on what you want to do by the code string.
这取决于您想通过代码字符串做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.