文件最后提交记录最后更新时间
docs: add OHOS API documentation (1290 APIs, 66 modules) Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
docs: remove platform support section from API docs Signed-off-by: zhangqingnan_codeing <zhangqingnan6@huawei.com> 1 个月前
README.md

Session API 列表

本模块包含 86 个 API。

Events(事件)

API 说明 鸿蒙支持
will-download 在 Electron 即将从 webContents 下载资源时触发。 支持
extension-loaded 在扩展加载完成后触发,当扩展被加入「已启用」集合时均会触发。 支持
extension-unloaded 在扩展卸载后触发,通常在调用 Session.removeExtension 时发生。 支持
extension-ready 在扩展加载完毕且支持扩展后台页面所需的浏览器状态初始化完成后触发。 支持
file-system-access-restricted 在文件系统访问受到限制时触发。 支持
preconnect 在渲染器请求预连接时触发,连接可能包含凭据。 支持
spellcheck-dictionary-initialized 在 hunspell 词典文件成功初始化(下载完成)后触发。 支持
spellcheck-dictionary-download-begin 在 hunspell 词典文件开始下载时触发。 支持
spellcheck-dictionary-download-success 在 hunspell 词典文件成功下载后触发。 支持
spellcheck-dictionary-download-failure 在 hunspell 词典文件下载失败时触发,可通过收集 netlog 并检查下载请求来排查原因。 支持
select-hid-device 在需要选择 HID 设备时触发,若帧已导航或销毁则可能为 null。 支持
hid-device-added 在新 HID 设备连接时触发,若帧已导航或销毁则可能为 null。 支持
hid-device-removed 在 HID 设备断开时触发,若帧已导航或销毁则可能为 null。 支持
hid-device-revoked 在 HIDDevice.forget() 调用后触发,可用于配合 setDevicePermissionHandler 维护持久化的权限存储。 支持
select-serial-port 在调用 navigator.serial.requestPort 需要选择串口时触发,应调用 callback 并传入端口 ID,传入空字符串将取消请求。 支持
serial-port-added 在 select-serial-port 事件触发后,若新串口在回调被调用前变为可用,则触发此事件,便于 UI 更新端口列表。 支持
serial-port-removed 在 select-serial-port 事件触发后,若某串口在回调被调用前断开,则触发此事件,便于 UI 从列表中移除该端口。 支持
serial-port-revoked 在串口权限被撤销时触发,若帧已导航或销毁则可能为 null。 支持
select-usb-device 在需要选择 USB 设备时触发,若帧已导航或销毁则可能为 null。 支持
usb-device-added 在 select-usb-device 事件触发后,若新 USB 设备在回调被调用前连接,则触发此事件,便于 UI 更新设备列表。 支持
usb-device-removed 在 select-usb-device 事件触发后,若某 USB 设备在回调被调用前断开,则触发此事件,便于 UI 从列表中移除该设备。 支持
usb-device-revoked 在 USBDevice.forget() 调用后触发,可用于配合 setDevicePermissionHandler 维护持久化的权限存储。 支持

Methods(方法)

API 说明 鸿蒙支持
session.fromPartition(partition[, options]) 返回 Session,根据 partition 字符串获取对应的 session 实例。 支持
session.fromPath(path[, options]) 返回 Session,根据指定的绝对路径获取对应的 session 实例。 支持
ses.getCacheSize() 返回 Promise,resolve 为当前 session 的缓存大小(字节)。 支持
ses.clearCache() 返回 Promise,在缓存清除完成后 resolve。 支持
ses.clearStorageData([options]) 返回 Promise,在存储数据清除完成后 resolve,支持清除 cookies、filesystem、indexdb、localstorage 等多种数据类型。 支持
ses.flushStorageData() 将未写入的 DOMStorage 数据立即刷写到磁盘。 支持
ses.setProxy(config) 返回 Promise,在代理设置完成后 resolve。 支持
ses.resolveHost(host, [options]) 返回 Promise,解析指定主机名对应的 IP 地址,解析器根据 IPv4/IPv6 设置选择 A 或 AAAA 记录。 支持
ses.resolveProxy(url) 返回 Promise,resolve 为指定 URL 的代理信息。 支持
ses.forceReloadProxyConfig() 返回 Promise,重置代理服务的所有内部状态并重新应用最新代理配置,若代理模式为 pac_script 则重新获取 PAC 脚本。 支持
ses.setDownloadPath(path) 设置文件下载保存目录,默认为各应用文件夹下的 Downloads 目录。 支持
ses.enableNetworkEmulation(options) 通过模拟指定的网络配置(含延迟节流)对 session 进行网络仿真。 支持
ses.preconnect(options) 向指定源预建立指定数量的 socket 连接。 支持
ses.closeAllConnections() 返回 Promise,在所有连接关闭后 resolve。 支持
ses.fetch(input[, init]) 返回 Promise,参见 Response。 支持
ses.disableNetworkEmulation() 停用当前 session 的网络仿真,恢复至原始网络配置。 支持
ses.setCertificateVerifyProc(proc) 为 session 设置证书验证处理器,除标准证书错误码外还支持特定的特殊码。 支持
ses.setPermissionRequestHandler(handler) 设置用于响应 session 权限请求的处理器,调用 callback(true) 允许权限,callback(false) 拒绝权限。 支持
ses.setPermissionCheckHandler(handler) 设置用于检查 session 权限的处理器,支持 audio、unknown 等权限类型。 支持
ses.setDisplayMediaRequestHandler(handler[, opts]) 设置 displayMedia 请求的处理器,可提供来自 DesktopCapturerSource 对象的媒体源。 支持
ses.setDevicePermissionHandler(handler) 设置用于响应设备权限检查的处理器,返回 true 允许设备访问,返回 false 拒绝。 支持
ses.setUSBProtectedClassesHandler(handler) 设置处理器以覆盖受保护 USB 类别的默认行为,返回值为应视为受保护(不在渲染器中开放)的 USB 类别字符串数组。 支持
ses.setBluetoothPairingHandler(handler) 设置蓝牙配对处理器,用于处理确认配对请求或验证 PIN 码等配对提示。 不支持
ses.clearHostResolverCache() 返回 Promise,在操作完成后 resolve。 支持
ses.allowNTLMCredentialsForDomains(domains) 配置允许使用 NTLM 集成身份验证的域名范围。 支持
ses.setUserAgent(userAgent[, acceptLanguages]) 覆盖当前 session 的 userAgent 和 acceptLanguages。 支持
ses.isPersistent() 返回 boolean,表示当前 session 是否为持久化 session。 支持
ses.getUserAgent() 返回 string,表示当前 session 的 User-Agent。 支持
ses.setSSLConfig(config) 配置 session 的 SSL 设置,包括连接远程服务器时允许的最低 SSL 版本(默认为 tls1)。 支持
ses.getBlobData(identifier) 返回 Promise,resolve 为 Blob 数据。 支持
ses.downloadURL(url[, options]) 发起对指定 URL 资源的下载,将生成可通过 will-download 事件访问的 DownloadItem。 支持
ses.createInterruptedDownload(options) 创建一个中断下载的恢复记录,options 中使用 Unix 纪元以来的秒数表示时间。 支持
ses.clearAuthCache() 返回 Promise,在 session 的 HTTP 身份验证缓存清除后 resolve。 支持
ses.setPreloads(preloads) 添加在正常 preload 脚本运行之前、对所有关联此 session 的 web 内容执行的脚本。 支持
ses.getPreloads() 返回 string[],包含已注册的所有 preload 脚本路径。 支持
ses.setCodeCachePath(path) 设置存储此 session 生成的 JS 代码缓存的目录,若目录不存在运行时将自动创建。 支持
ses.clearCodeCaches(options) 返回 Promise,在代码缓存清除完成后 resolve。 支持
ses.getSharedDictionaryUsageInfo() 返回 Promise<SharedDictionaryInfo[]>,包含 Chromium 网络服务存储中的共享字典使用信息列表。 支持
ses.getSharedDictionaryInfo(options) 返回 Promise<SharedDictionaryInfo[]>,包含 Chromium 网络服务存储中的共享字典信息列表。 支持
ses.clearSharedDictionaryCache() 返回 Promise,在内存和磁盘上的字典缓存均清除后 resolve。 支持
ses.clearSharedDictionaryCacheForIsolationKey(options) 返回 Promise,在指定隔离键对应的内存和磁盘字典缓存清除后 resolve。 支持
ses.setSpellCheckerEnabled(enable) 设置是否启用内置拼写检查器。 支持
ses.isSpellCheckerEnabled() 返回 boolean,表示内置拼写检查器是否已启用。 支持
ses.setSpellCheckerLanguages(languages) 设置拼写检查器使用的语言,需传入语言代码数组,因为内置拼写检查器不会自动检测用户输入的语言。 支持
ses.getSpellCheckerLanguages() 返回 string[],包含当前已启用拼写检查的语言代码列表,若列表为空则使用默认语言。 支持
ses.setSpellCheckerDictionaryDownloadURL(url) 覆盖 hunspell 词典的下载地址,默认从 Chromium CDN 下载,可通过此 API 指向自托管版本。 支持
ses.listWordsInSpellCheckerDictionary() 返回 Promise<string[]>,包含应用自定义词典中的所有单词。 支持
ses.addWordToSpellCheckerDictionary(word) 返回 boolean,表示单词是否成功写入自定义词典。 支持
ses.removeWordFromSpellCheckerDictionary(word) 返回 boolean,表示单词是否成功从自定义词典中移除。 支持
ses.loadExtension(path[, options]) 返回 Promise,在扩展加载完成后 resolve,支持为文件页面注入内容脚本等特性。 支持
ses.removeExtension(extensionId) 卸载指定扩展。 支持
ses.getExtension(extensionId) 返回 Extension null,获取指定 ID 对应的已加载扩展。
ses.getAllExtensions() 返回 Extension[],包含所有已加载的扩展列表。 支持
ses.getStoragePath() 返回 string null,表示该 session 数据持久化存储的绝对文件系统路径。
ses.clearData([options]) 返回 Promise,在所有数据清除完成后 resolve,可能包含 Chromium BrowsingDataRemover 列出的各类数据。 支持

Properties(属性)

API 说明 鸿蒙支持
session.defaultSession Session 对象,表示应用的默认 session。 支持
ses.availableSpellCheckerLanguages 字符串数组,包含所有已知可用的拼写检查语言代码,向 setSpellCheckerLanguages 传入不在此列表中的语言代码将报错。 支持
ses.spellCheckerEnabled 布尔值,表示内置拼写检查器是否已启用。 支持
ses.storagePath 字符串或 null,表示该 session 数据在磁盘上的绝对存储路径,内存 session 返回 null。 支持
ses.cookies 该 session 对应的 Cookies 对象。 支持
ses.serviceWorkers 该 session 对应的 ServiceWorkers 对象。 支持
ses.webRequest 该 session 对应的 WebRequest 对象。 支持
ses.protocol 该 session 对应的 Protocol 对象。 支持
ses.netLog 该 session 对应的 NetLog 对象。 支持