跳到主要内容

PWA🧪

该域允许与浏览器交互以控制''PWA''。

EN
This domain allows interacting with the browser to control PWAs.

✅️️ Methods

🔨PWA.changeAppUserSettings

根据其 manifestId 识别出的网络应用,更改其用户设置。如果该应用未安装,此命令将返回错误。未设置的参数将被忽略;无法识别的值将导致错误。

与网络应用清单文件中定义的设置不同,这些设置由浏览器提供并由用户控制,它们会影响浏览器处理网络应用的方式。

请参阅每个参数的注释。

EN
Changes user settings of the web app identified by its manifestId. If the app was not installed, this command returns an error. Unset parameters will be ignored; unrecognized values will cause an error.
Unlike the ones defined in the manifest files of the web apps, these settings are provided by the browser and controlled by the users, they impact the way the browser handling the web apps.
See the comment of each parameter.
参数必填标记类型描述原文
manifestId✔️string
linkCapturingboolean如果用户允许应用范围内(或在清单具有范围扩展且启用了 DesktopPWAsLinkCapturingWithScopeExtensionsWebAppEnableScopeExtensions 标志时,扩展范围内)用户点击的链接,
请注意,此 API 不支持将 linkCapturing 重置为初始值,卸载并重新安装 Web 应用可将其重置。
TODO(crbug.com/339453269):目前尚不支持在 ChromeOS 上设置此值。
ENIf user allows the links clicked on by the user in the app's scope, or extended scope if the manifest has scope extensions and the flags DesktopPWAsLinkCapturingWithScopeExtensions and WebAppEnableScopeExtensions are enabled.
Note, the API does not support resetting the linkCapturing to the initial value, uninstalling and installing the web app again will reset it.
TODO(crbug.com/339453269): Setting this value on ChromeOS is not supported yet.
displayModeDisplayMode

🔨PWA.getOsAppState

返回给定清单ID对应的以下操作系统状态。

EN
Returns the following OS state for the given manifest id.
参数必填标记类型描述原文
manifestId✔️string来自Web应用程序清单文件的ID,通常是安装该Web应用程序的站点URL。参见https://web.dev/learn/pwa/web-app-manifest
ENThe id from the webapp's manifest file, commonly it's the url of the site installing the webapp. See https://web.dev/learn/pwa/web-app-manifest.
返回对象类型描述原文
badgeCountinteger
fileHandlersarray[FileHandler]

🔨PWA.install

安装给定的清单标识,可选择使用给定的安装URL或捆绑包URL

IWA特定安装说明:manifestId对应isolated-app:// + web_package::SignedWebBundleId

文件安装模式:installUrlOrBundleUrl可以是file://或http(s)://格式,指向已签名的网络捆绑包(.swbn)。此时SignedWebBundleId必须与.swbn文件的签名密钥对应。

开发代理安装模式:installUrlOrBundleUrl必须是提供开发模式IWA的http(s)://地址。web_package::SignedWebBundleId必须是开发代理类型。

开发代理模式的优势在于:对IWA的所有更改将自动反映在运行中的应用中,无需重新安装。

生成代理模式的捆绑包ID:
- 生成32个随机字节
- 按照文档https://github.com/WICG/isolated-web-apps/blob/main/Scheme.md#suffix在末尾添加特定后缀
- 使用无填充Base32编码整个序列

如果Chrome未处于IWA开发模式,无论白名单状态如何,安装都将失败。

EN
Installs the given manifest identity, optionally using the given installUrlOrBundleUrl
IWA-specific install description: manifestId corresponds to isolated-app:// + web_package::SignedWebBundleId
File installation mode: The installUrlOrBundleUrl can be either file:// or http(s):// pointing to a signed web bundle (.swbn). In this case SignedWebBundleId must correspond to The .swbn file's signing key.
Dev proxy installation mode: installUrlOrBundleUrl must be http(s):// that serves dev mode IWA. web_package::SignedWebBundleId must be of type dev proxy.
The advantage of dev proxy mode is that all changes to IWA automatically will be reflected in the running app without reinstallation.
To generate bundle id for proxy mode:
- Generate 32 random bytes.
- Add a specific suffix at the end following the documentation https://github.com/WICG/isolated-web-apps/blob/main/Scheme.md#suffix
- Encode the entire sequence using Base32 without padding.

If Chrome is not in IWA dev mode, the installation will fail, regardless of the state of the allowlist.
参数必填标记类型描述原文
manifestId✔️string
installUrlOrBundleUrlstring应用程序或捆绑包的位置,覆盖了从manifestId派生的位置。
ENThe location of the app or bundle overriding the one derived from the manifestId.

🔨PWA.launch

启动已安装的Web应用程序,如果提供了URL,则会在同一Web应用程序中打开该URL,而不是默认的起始URL。返回一个页面目标ID(Target.TargetID),可通过Target.attachToTarget或类似API进行连接。

EN
Launches the installed web app, or an url in the same web app instead of the default start url if it is provided. Returns a page Target.TargetID which can be used to attach to via Target.attachToTarget or similar APIs.
参数必填标记类型描述原文
manifestId✔️string
urlstring
返回对象类型描述原文
targetIdTarget.TargetID作为结果创建的标签页目标的ID。
ENID of the tab target created as a result.

🔨PWA.launchFilesInApp

通过其manifestId标识的已安装Web应用程序打开一个或多个本地文件。该Web应用程序需要注册文件处理程序来处理这些文件。API返回一个或多个页面Target.TargetID,可通过Target.attachToTarget或类似API进行连接。如果参数中的某些文件无法被Web应用程序处理,它们将被忽略。如果所有文件都无法处理,此API将返回错误。如果未提供文件作为参数,此API同样会返回错误。

根据清单文件中文件处理程序的定义,一个Target.TargetID可能代表处理一个或多个文件的页面。返回的Target.TargetID顺序无法保证。

TODO(crbug.com/339454034):检查输入文件的存在性。

EN
Opens one or more local files from an installed web app identified by its manifestId. The web app needs to have file handlers registered to process the files. The API returns one or more page Target.TargetIDs which can be used to attach to via Target.attachToTarget or similar APIs. If some files in the parameters cannot be handled by the web app, they will be ignored. If none of the files can be handled, this API returns an error. If no files are provided as the parameter, this API also returns an error.
According to the definition of the file handlers in the manifest file, one Target.TargetID may represent a page handling one or more files. The order of the returned Target.TargetIDs is not guaranteed.
TODO(crbug.com/339454034): Check the existences of the input files.
参数必填标记类型描述原文
manifestId✔️string
files✔️array[string]
返回对象类型描述原文
targetIdsarray[Target.TargetID]作为结果创建的标签页目标的ID。
ENIDs of the tab targets created as the result.

🔨PWA.openCurrentPageInApp

在当前页面目标上,以清单ID标识的Web应用程序中打开当前页面。此函数会立即返回,无需等待应用程序加载完成。

EN
Opens the current page in its web app identified by the manifest id, needs to be called on a page target. This function returns immediately without waiting for the app to finish loading.
参数必填标记类型描述原文
manifestId✔️string

🔨PWA.uninstall

卸载给定的 ''manifest_id'' 并关闭所有已打开的应用程序窗口。

EN
Uninstalls the given manifest_id and closes any opened app windows.
参数必填标记类型描述原文
manifestId✔️string

✅️️ Types

📌PWA.DisplayMode

如果用户倾向于在浏览器或应用程序窗口中打开应用。
允许的值:standalonebrowser

EN
If user prefers opening the app in browser or an app window.
Allowed Values: standalone, browser

返回类型:string


📌PWA.FileHandler

返回类型:object

属性必填标记类型描述原文
action✔️string
accepts✔️array[FileHandlerAccept]
displayName✔️string

📌PWA.FileHandlerAccept

以下类型是 https://crsrc.org/c/chrome/browser/web_applications/proto/web_app_os_integration_state.proto;drc=9910d3be894c8f142c977ba1023f30a656bc13fc;l=67 的副本

EN

返回类型:object

属性必填标记类型描述原文
mediaType✔️string根据https://www.iana.org/assignments/media-types/media-types.xhtml更新的MIME类型新名称
ENNew name of the mimetype according to https://www.iana.org/assignments/media-types/media-types.xhtml
fileExtensions✔️array[string]