通过 Google Chrome 扩展访问本地文件?
我需要从本地文件将名称列表加载到我的 google chrome 扩展中, 这怎么能做到呢?如果文件本身附带扩展名怎么办?
I need to load a list of names into my google chrome extension from a local file,
How can this be done? what if the file is shipped with the extension itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的扩展程序附带此文件,那么您只需在后台页面内使用
XMLHttpRequest
加载它(使用相对路径,/
是扩展程序根文件夹)。您还可以将文件设置为 javascript (
var config=[...]
),然后使用将其加载到后台页面。
If this file is shipped with your extension then you can just load it with
XMLHttpRequest
inside background page (use relative paths, with/
being extension root folder).You can also make your file to be javascript (
var config=[...]
) and just load it with<script>
into background page.假设您的json文件是以下文件夹中的names.json
在manifest.json中添加资源路径
使用fectch() API来访问资源
Say your json file is names.json in the following folder
In manifest.json add path to the resource
Use fectch() API to access the resource