我如何使用 chrome 扩展 API 从后台发送请求到后台?
现在我通过在后台创建 iframe 来实现该解决方案,因此它处理请求,但它的解决方案非常不受信任+过度杀伤,我有大约 400 个文件,每个文件都使用 sendRequest 方法,我无法将它们合并为一个文件,因为它们是通过依赖加载器(Pub Sub 架构)加载的,现在有另一个解决方案,我已经使用 MessageChannel 和 MessageChannel 对其进行了概念验证。 postMessage 在后台,但问题是对于 contentScript 或我定义的前台,我仍然需要使用 chrome API 在后台和前台之间传递消息。
我该如何解决它?:)
Right now i implemented the solution by creating iframes on the background, so it process the request, but its very untrusted solution + overkill, i have something like 400 files that every one of them use sendRequest method, i can't combine them to one file because they load by dependency loader(Pub Sub architecture), now there is another solution that i already made him Proof-of-concept, using MessageChannel & postMessage in the background, but the problem is that for the contentScript or on my definition frontstage, i still need to use chrome API to pass messages between backstage and frontstage.
How do i solve it?:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我明白你的意思。你有几个js文件,它们都在后台页面,并希望它们互相
sendRequest
。您可以通过不实际执行sendRequest
而是调用函数来实现此目的。举个例子可能会更好:而不是这个:
还有这个:
你这样做:
还有这个:
当然,不在后台页面上的脚本仍然会执行
sendRequest
s。I think I know what you mean. You have several js files that are all on the background page, and want them to
sendRequest
to eachother. You can do this by not actually doingsendRequest
s, but calling a function. It's probably better with an example:Instead of this:
And this:
You do this:
And this:
Of course scripts that are not on the background page will still do
sendRequest
s.