diff --git a/zh-cn/application-dev/reference/apis-arkweb/js-apis-webview.md b/zh-cn/application-dev/reference/apis-arkweb/js-apis-webview.md index 78c190d135c1a1dbd8c59f03b52dedb4962c5996..98f1d2a64036d59a5431adb8a54cddb1b8cd88ff 100644 --- a/zh-cn/application-dev/reference/apis-arkweb/js-apis-webview.md +++ b/zh-cn/application-dev/reference/apis-arkweb/js-apis-webview.md @@ -5377,7 +5377,7 @@ static setConnectionTimeout(timeout: number): void | 参数名 | 类型 | 必填 | 说明 | | ---------------| ------- | ---- | ------------- | -| timeout | number | 是 | socket连接超时时间,以秒为单位。 | +| timeout | number | 是 | socket连接超时时间,以秒为单位,socket必须为大于0的整数。 | **示例:** @@ -13844,6 +13844,48 @@ struct WebComponent { } } ``` + +### warmupServiceWorker12+ + +static warmupServiceWorker(url: string): void + +预热ServiceWorker,以提升首屏页面的加载速度(仅限于会使用ServiceWorker的页面)。在加载url之前调用此API。 + +**系统能力:** SystemCapability.Web.Webview.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ---------------| ------- | ---- | ------------- | +| url | string | 是 | 需要预热ServiceWorker的url。| + +**错误码:** + +以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md). + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 17100002 | Invalid url. | + +**示例:** + +```ts +// xxx.ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import webview from '@ohos.web.webview'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import Want from '@ohos.app.ability.Want'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + console.log("EntryAbility onCreate"); + webview.WebviewController.initializeWebEngine(); + webview.WebviewController.warmupServiceWorker("https://www.example.com"); + AppStorage.setOrCreate("abilityWant", want); + } +} +``` + ### onRequestStop12+ onRequestStop(callback: Callback\): void