Firefox Local Mode
Firefox Local Mode
Firefox DevTools User Docs Local Mode Report an issue / View page source Local Mode What is the “Local Mode” This feature allows you to register multiple mappings in order to load local files through custom https:// URLs. This prevents having to spawn a HTTP server to test a web page. This makes it easy to test all Web APIs, including the ones being restricted to Secure Contexts (i.e. using https). This also helps having many distinct origins (domain) for each experiment / project and have dedicated storage/cookies for each. These mappings are only accessible from Firefox (this can’t be used by any other program, or malicious software on your computer/local network). These mappings are only functional when DevTools are opened.
Firefox 开发者工具用户文档 本地模式 报告问题 / 查看页面源代码 本地模式 什么是“本地模式” 此功能允许您注册多个映射,以便通过自定义的 https:// URL 加载本地文件。这避免了为了测试网页而必须启动 HTTP 服务器的麻烦。这使得测试所有 Web API 变得容易,包括那些仅限于安全上下文(即使用 https)的 API。这也助于为每个实验/项目拥有许多不同的源(域),并为每个源拥有专用的存储/Cookie。这些映射只能从 Firefox 访问(其他程序或您计算机/本地网络上的恶意软件无法使用此功能)。这些映射仅在打开开发者工具时才起作用。
How to use the “Local Mode” This feature shipped in Firefox 153. You can register mappings from DevTools’ Options panel: From there you can register as many mappings as you need. Each mapping defines: the origin (domain) The custom origin to expose via https URL. the local folder The local folder where to load files from. On the screenshot, it loads https://firefox.localhost from /home/alex/app.
如何使用“本地模式” 此功能随 Firefox 153 发布。您可以从开发者工具的选项面板注册映射:从那里您可以根据需要注册任意数量的映射。每个映射定义了:源(域)通过 https URL 公开的自定义源。本地文件夹从中加载文件的本地文件夹。在截图中,它从 /home/alex/app 加载 https://firefox.localhost。
Loading file URL notification When loading any file:// URL with DevTools opened, you should see the following notification at the top of DevTools: The first action Add To Settings will bring you to the Options panel and register a new mapping for the loaded file URL. The second action Try it will register a transient mapping to load the current file or folder from a https URL. The mapping will disappear as soon as you close DevTools or Firefox.
加载 file:// URL 通知 当在打开开发者工具的情况下加载任何 file:// URL 时,您应该会在开发者工具顶部看到以下通知:第一个操作“添加到设置”将带您进入选项面板,并为已加载的 file:// URL 注册一个新映射。第二个操作“尝试一下”将注册一个临时映射,以从 https URL 加载当前文件或文件夹。一旦您关闭开发者工具或 Firefox,该映射就会消失。
Manage mappings via preferences Mappings can also be managed in about:config via preferences, so that you can easily import and transfer them between profiles, or via automation. Each mapping is defined by three preferences: devtools.local-mode.mappings.${index}.origin: string for the mapping’s origin. (e.g. “firefox.localhost”) devtools.local-mode.mappings.${index}.path: string for the absolute path to local folder (e.g. “/home/hello-world”) devtools.local-mode.mappings.${index}.disabled: optional boolean to disable this mapping and where ${index} is an incremental integer counter to uniquely identify each mapping. Here is an example of mappings you can control from about:config:
通过首选项管理映射 映射也可以在 about:config 中通过首选项进行管理,这样您可以轻松地在配置文件之间导入和传输它们,或者通过自动化进行管理。每个映射由三个首选项定义:devtools.local-mode.mappings.${index}.origin:映射源的字符串。(例如“firefox.localhost”)devtools.local-mode.mappings.${index}.path:本地文件夹绝对路径的字符串(例如“/home/hello-world”)devtools.local-mode.mappings.${index}.disabled:用于禁用此映射的可选布尔值,其中 ${index} 是用于唯一标识每个映射的递增整数计数器。以下是您可以从 about:config 控制的映射示例: