Are there any ways to create a server hosted at 127.0.0.1 which will host a folder from within a Chrome (non-legacy) Extension? We want the extension to be used as part within the dev team, so a non-legacy version is what we are looking at.
有没有办法创建一个托管在127.0.0.1的服务器,它将在Chrome(非传统)扩展中托管一个文件夹?我们希望扩展可以作为开发团队的一部分使用,因此我们正在研究非遗留版本。
Followed this link: https://github.com/kzahel/web-server-chrome which gave insights on how to start a server. The problem is, everytime we start the server at the IP:port, we have to manually configure the folder path. But instead, we would want the Extension to itself configure the folder path which may even be hard-coded in the JS files.
点击此链接:https://github.com/kzahel/web-server-chrome,它提供了有关如何启动服务器的见解。问题是,每次我们在IP:端口启动服务器时,我们都必须手动配置文件夹路径。但相反,我们希望Extension自身配置文件夹路径,甚至可以在JS文件中进行硬编码。
1 个解决方案
#1
Are there any ways to create a server hosted at 127.0.0.1 which will host a folder from within a Chrome (non-legacy) Extension?
有没有办法创建一个托管在127.0.0.1的服务器,它将在Chrome(非传统)扩展中托管一个文件夹?
No, you can't do that with an extension at all. You need a Chrome App to be able to use sockets
API, and that's the only way to expose a server.
不,你根本无法做到这一点。您需要Chrome应用程序才能使用套接字API,这是公开服务器的唯一方法。
But instead, we would want the Extension to itself configure the folder path which may even be hard-coded in the JS files.
但相反,我们希望Extension自身配置文件夹路径,甚至可以在JS文件中进行硬编码。
You can't hard-code a path to an arbitrary local file. It's a security feature - you have to ask for access at least once. You can retain the entry afterwards.
您不能将路径硬编码到任意本地文件。这是一项安全功能 - 您必须至少要求访问一次。您可以在之后保留该条目。
However, you mention "host a folder from within a Chrome (non-legacy) Extension". If you mean that the folder itself is part of the extention's (or rather, app's) files, then yes, you can obtain access automatically. Except instead of fileSystem
API, you need to call chrome.runtime.getPackageDirectoryEntry()
to get the root of your app's folder.
但是,您提到“在Chrome(非传统)扩展程序中托管文件夹”。如果您的意思是文件夹本身是扩展(或更确切地说,应用程序)文件的一部分,那么是的,您可以自动获取访问权限。除了fileSystem API之外,您需要调用chrome.runtime.getPackageDirectoryEntry()来获取应用程序文件夹的根目录。
Please note that you can only obtain read-only access this way.
请注意,您只能通过这种方式获得只读访问权限。
#1
Are there any ways to create a server hosted at 127.0.0.1 which will host a folder from within a Chrome (non-legacy) Extension?
有没有办法创建一个托管在127.0.0.1的服务器,它将在Chrome(非传统)扩展中托管一个文件夹?
No, you can't do that with an extension at all. You need a Chrome App to be able to use sockets
API, and that's the only way to expose a server.
不,你根本无法做到这一点。您需要Chrome应用程序才能使用套接字API,这是公开服务器的唯一方法。
But instead, we would want the Extension to itself configure the folder path which may even be hard-coded in the JS files.
但相反,我们希望Extension自身配置文件夹路径,甚至可以在JS文件中进行硬编码。
You can't hard-code a path to an arbitrary local file. It's a security feature - you have to ask for access at least once. You can retain the entry afterwards.
您不能将路径硬编码到任意本地文件。这是一项安全功能 - 您必须至少要求访问一次。您可以在之后保留该条目。
However, you mention "host a folder from within a Chrome (non-legacy) Extension". If you mean that the folder itself is part of the extention's (or rather, app's) files, then yes, you can obtain access automatically. Except instead of fileSystem
API, you need to call chrome.runtime.getPackageDirectoryEntry()
to get the root of your app's folder.
但是,您提到“在Chrome(非传统)扩展程序中托管文件夹”。如果您的意思是文件夹本身是扩展(或更确切地说,应用程序)文件的一部分,那么是的,您可以自动获取访问权限。除了fileSystem API之外,您需要调用chrome.runtime.getPackageDirectoryEntry()来获取应用程序文件夹的根目录。
Please note that you can only obtain read-only access this way.
请注意,您只能通过这种方式获得只读访问权限。