简体   繁体   English

Chrome manifest v3 - 是否有可行的解决方法在 Chrome 扩展中使用 Google 的文件选择器?

[英]Chrome manifest v3 - is there a viable workaround to use Google's File Picker in a Chrome extension?

My searches have turned up nothing concrete.我的搜索没有任何具体结果。 My extension uses Google's file picker to allow the user to browse their sheets and choose a desired file to write some data to, which manifest v3 breaks because of some GAPI limitations.我的扩展使用谷歌的文件选择器来允许用户浏览他们的工作表并选择一个想要的文件来写入一些数据,由于一些 GAPI 限制,清单 v3 会中断。 Unless I've missed something obvious, there does not seem to be a simple workaround or method for this to migrate to v3 -- it just seems to be disallowed.除非我遗漏了一些明显的东西,否则似乎没有一个简单的解决方法或方法可以将其迁移到 v3——这似乎是不允许的。

I'm not asking if there's a way to do something that they intend to not be possible (even though I doubt such a thing would exist with Google) but I'm optimistically hoping that maybe there is some hacky/annoying workaround that still fits within their rules.我不是在问是否有办法做他们打算不可能的事情(即使我怀疑谷歌会存在这样的事情)但我乐观地希望也许有一些 hacky/恼人的解决方法仍然适合在他们的规则范围内。 If I absolutely have to just allow them to set a sheet URL manually I will...I'm just trying to avoid it.如果我绝对必须允许他们手动设置工作表 URL,我会......我只是想避免它。

Any tips or suggestions would be appreciated.任何提示或建议将不胜感激。

You may have to test it yourself to make sure there are no weird behaviors, but Google has some recommendations regarding this in their migration guide :您可能必须自己测试以确保没有奇怪的行为,但谷歌在他们的迁移指南中对此有一些建议:

In Manifest V3, all of your extension's logic must be included in the extension.在 Manifest V3 中,所有扩展的逻辑都必须包含在扩展中。 You can no longer load and execute a remotely hosted file.您不能再加载和执行远程托管文件。 A number of alternative approaches are available, depending on your use case and the reason for remote hosting.根据您的用例和远程托管的原因,可以使用许多替代方法。 Here are approaches to consider:以下是需要考虑的方法:

Configuration-driven features and logic配置驱动的特性和逻辑

In this approach, your extension loads a remote configuration (for example a JSON file) at runtime and caches the configuration locally.在这种方法中,您的扩展在运行时加载远程配置(例如 JSON 文件)并在本地缓存配置。 The extension then uses this cached configuration to decide which features to enable.然后,扩展使用此缓存配置来决定启用哪些功能。

Externalize logic with a remote service使用远程服务外部化逻辑

Consider migrating application logic from the extension to a remote web service that your extension can call.考虑将应用程序逻辑从扩展迁移到您的扩展可以调用的远程 Web 服务。 (Essentially a form of message passing.) This provides you the ability to keep code private and change the code on demand while avoiding the extra overhead of resubmitting to the Chrome Web Store. (本质上是消息传递的一种形式。)这使您能够保持代码的私密性并按需更改代码,同时避免重新提交到 Chrome 网上应用店的额外开销。

Bundle third-party libraries捆绑第三方库

If you are using a popular framework like React or Bootstrap, you can download the minified files, add them to your project and import them locally.如果您使用的是 React 或 Bootstrap 等流行框架,您可以下载压缩文件,将它们添加到您的项目中并在本地导入它们。

For your case, option #3 seems like the easiest.对于您的情况,选项 #3 似乎是最简单的。 Looking at the Google Picker API documentation it only uses two relatively small script files, https://apis.google.com/js/api.js and https://accounts.google.com/gsi/client .查看 Google Picker API文档,它只使用了两个相对较小的脚本文件, https://apis.google.com/js/api.jshttps://accounts.google.com/gsi/client You could try to bundle these in your Chrome extension and call the methods locally.您可以尝试将这些捆绑在您的 Chrome 扩展程序中并在本地调用这些方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM