# Microsoft Edge 上的 PWA（侧边栏、商店）

> Edge 如何安装和管理 PWA、如何通过商店打包和检测侧边栏，以及安装按钮如何提供回退。

Microsoft Edge 可以从地址栏或 Microsoft Store 安装 PWA。在 Windows 上，Edge 还负责管理已安装的 PWA。网页可以检测自己是否位于 Edge 侧边栏，不过这项功能已经弃用。

## 工作原理

Edge 判定站点是可安装的 PWA 后，会在地址栏显示 **App available** 图标。选择该图标后，再选择 **Install** 即可安装 PWA 并在 Windows 中运行（[Use Progressive Web Apps in Microsoft Edge](https://learn.microsoft.com/en-us/microsoft-edge/progressive-web-apps/ux)，Microsoft Learn）。

任意网站都可以从 **Settings and more** > **More tools** > **Apps** > **Install this site as an app** 安装。安装后到 `edge://apps` 查看应用（[Install, manage, or uninstall apps in Microsoft Edge](https://support.microsoft.com/en-us/edge/install-manage-or-uninstall-apps-in-microsoft-edge)，Microsoft Support）。

Edge 在 `edge://apps` 和 **Settings and more** > **More tools** > **Apps** > **View apps** 中列出已安装的 PWA。Microsoft Support 说明，`edge://apps` 可按安装日期、最近使用时间或名称排序，并可从应用详情中启用 **Auto-start on device login**。Windows 任务栏、开始菜单、Alt+Tab 切换器和 Apps & features 设置中都会显示已安装的 PWA。已安装窗口的 **Settings and more** 按钮会打开 **App info** 菜单。菜单中包括应用图标、名称和发布者，**Pin to taskbar**、**Pin to Start** 与 **App settings** 命令，以及 **Privacy**、**Extensions** 和 **More tools** 子菜单。PWA 还可在任务栏右键菜单中公开 manifest shortcuts（[Use Progressive Web Apps in Microsoft Edge](https://learn.microsoft.com/en-us/microsoft-edge/progressive-web-apps/ux)，Microsoft Learn）。

按微软的 Store 流程，先在 Partner Center 中创建应用预留。然后用 PWABuilder 打包 PWA，把包提交到 Microsoft Store。微软说明，按这个流程发布不需要更改代码（[Publish a PWA to the Microsoft Store](https://learn.microsoft.com/en-us/microsoft-edge/progressive-web-apps/how-to/microsoft-store)，Microsoft Learn）。PWABuilder 提供的 `.zip` 压缩包包含 `.msixbundle` 和 `.classic.appxbundle`；微软要求发布者提交这两个包文件。Store 审核通常需要 24 到 48 小时。

Store 安装包把起始 URL 固定在主域名上。启动后跳转到地区专用域名，会超出 scope，Edge 随即显示 URL 和页面标题，微软文档对此有说明。

如果先在 Edge 中跳转到地区专用域名，再从浏览器安装 PWA，应用就会直接从那个域名启动。

`edge_side_panel` manifest 成员曾用于让 PWA 选择加入 Edge 侧边栏固定功能。微软的侧边栏文档在 2026-07 更新中把该功能标为正在弃用。文档记录的侧边栏默认最小宽度为 376 像素。应用可以用 `edge_side_panel.preferred_width` 请求初始宽度；用户可以把它调整到比首选宽度更宽，也可以缩小到 376 像素下限。该文档还要求页面在 `Sec-CH-UA` 或 `navigator.userAgentData.brands` 中查找 `Edge Side Panel` 品牌，以检测侧边栏上下文，并说明侧边栏应用默认接收桌面端提示 `Sec-CH-UA-Mobile: ?0`。

## 平台支持

按微软文档，Microsoft Edge 支持从地址栏安装和管理 PWA；在 Windows 上还与任务栏、开始菜单、Alt+Tab、Apps & features 和 Microsoft Store 集成。Edge UX 文档还列出一项 Windows 限制：在 FSLogix 环境中可以安装 PWA，但用户注销并重新登录后，已安装的 PWA 会消失。侧边栏上下文是 Edge 专有功能，已经弃用。

## 示例

仅在 User-Agent Client Hints 可用时读取品牌列表。回退分支选择普通布局，但不据此断言页面是否已安装。

### 检测 Edge 侧边栏品牌

```js
function isEdgeSidebar() {
  const brands = navigator.userAgentData?.brands;
  if (!brands) {
    return false;
  }

  return brands.some(({ brand }) => brand === 'Edge Side Panel');
}

const sidebar = isEdgeSidebar();
document.documentElement.classList.toggle('edge-sidebar', sidebar);
```

微软建议优先用 User-Agent Client Hints 检测，解析 User-Agent 字符串是次选方案。

### Edge 提供事件后显示安装按钮

在 `beforeinstallprompt` 触发前保持按钮隐藏。事件不可用时，代码把浏览器自己的安装界面留作回退。

```js
const installButton = document.querySelector('#install');
let installEvent;

window.addEventListener('beforeinstallprompt', (event) => {
  event.preventDefault();
  installEvent = event;
  installButton.hidden = false;
});

installButton.addEventListener('click', async () => {
  if (!installEvent) return;
  await installEvent.prompt();
  installEvent = undefined;
  installButton.hidden = true;
});
```

MDN 把 `beforeinstallprompt` 标记为有限可用，并指出调用 `preventDefault()` 在部分平台上可阻止浏览器提供的安装界面出现。所以这个事件不能用作通用安装接口。

:::caution
微软的 Store 文档给出了从 Microsoft Store 安装的 PWA 启动时，Microsoft Edge 随首次导航发送的请求头：`Referer: app-info://platform/microsoft-store`。文档说明可通过 `document.referrer` 读取该值，并用它测量来自 Microsoft Store 安装 PWA 的流量；文档没有为该行为注明 Edge 构建版本或 Windows 版本（[Publish a PWA to the Microsoft Store](https://learn.microsoft.com/en-us/microsoft-edge/progressive-web-apps/how-to/microsoft-store)，learn.microsoft.com）。
:::

检测时要在 `Sec-CH-UA` 标头中查找文档给出的 `Edge Side Panel` 品牌。文档没有规定完整标头的固定字符串。自定义安装事件的浏览器与平台证据汇总在[安装提示兼容性](/zh/compatibility/install-prompt/)中。

## 另请参阅

- [Use Progressive Web Apps in Microsoft Edge](https://learn.microsoft.com/en-us/microsoft-edge/progressive-web-apps/ux)（learn.microsoft.com）
- [Publish a PWA to the Microsoft Store](https://learn.microsoft.com/en-us/microsoft-edge/progressive-web-apps/how-to/microsoft-store)（learn.microsoft.com）
- [Build a PWA for the sidebar in Microsoft Edge](https://learn.microsoft.com/en-us/microsoft-edge/progressive-web-apps/how-to/sidebar)（learn.microsoft.com）
- [Manifest edge_side_panel](/zh/reference/manifest/edge-side-panel/)
- [Windows 上的 PWA](/zh/reference/platforms/windows/)
- [桌面端安装](/zh/reference/installation/desktop-install/)