From 6caed1c6d50e3d6549d2bfebb0e483a68d650dce Mon Sep 17 00:00:00 2001 From: cpeng1101 Date: Fri, 15 Aug 2025 11:02:54 +0800 Subject: [PATCH] =?UTF-8?q?URL=E5=8F=82=E6=95=B0=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cpeng1101 --- api/@ohos.web.webview.d.ts | 87 +++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/api/@ohos.web.webview.d.ts b/api/@ohos.web.webview.d.ts index 93c947d2b0..56cfb91ac7 100644 --- a/api/@ohos.web.webview.d.ts +++ b/api/@ohos.web.webview.d.ts @@ -5572,6 +5572,18 @@ declare namespace webview { * @atomicservice * @since 11 */ + /** + * Prefetch the resources required by the page, but will not execute js or render the page. + * @param { string } url - Which url to preresolve/preconnect. + * @param { Array } [additionalHeaders] - Additional HTTP request header of the URL. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * @throws { BusinessError } 17100002 - URL error. The webpage corresponding to the URL is invalid, or the URL + * length exceeds 2*1024*1024. + * @syscap SystemCapability.Web.Webview.Core + * @atomicservice + * @since 22 dynamic&static + */ prefetchPage(url: string, additionalHeaders?: Array): void; /** @@ -5597,7 +5609,21 @@ declare namespace webview { * @atomicservice * @since 11 */ - static prepareForPageLoad(url: string, preconnectable: boolean, numSockets: number): void; + /** + * Preresolve or Preconnect the url. This API can be called before loading the url to make loading faster. + * @param { string } url - Which url to preresolve/preconnect. + * @param { boolean } preconnectable - Indicates whether to preconnect. + * @param { int } numSockets - If preconnectable is true, this parameter indicates the number of sockets + * to be preconnected. + * @throws { BusinessError } 17100002 - URL error. The webpage corresponding to the URL is invalid, or the URL + * length exceeds 2*1024*1024. + * @throws { BusinessError } 17100013 - The number of preconnect sockets is invalid. + * @static + * @syscap SystemCapability.Web.Webview.Core + * @atomicservice + * @since 22 dynamic&static + */ + static prepareForPageLoad(url: string, preconnectable: boolean, numSockets: int): void; /** * Set custom user agent. @@ -5701,6 +5727,18 @@ declare namespace webview { * @since arkts {'1.1':'18', '1.2':'20'} * @arkts 1.1&1.2 */ + /** + * Start a download. + * @param { string } url - The download url. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * @throws { BusinessError } 17100002 - URL error. The webpage corresponding to the URL is invalid, or the URL + * length exceeds 2*1024*1024. + * @syscap SystemCapability.Web.Webview.Core + * @crossplatform + * @atomicservice + * @since 22 dynamic&static + */ startDownload(url: string): void; /** @@ -6184,8 +6222,30 @@ declare namespace webview { * @atomicservice * @since 12 */ + /** + * Prefetches resource requests based on specified request information and additional HTTP request headers, + * saves the requests to the memory cache, and specifies the cache key and validity period to accelerate loading. + * Currently, only POST requests whose Content-Type is application/x-www-form-urlencoded are supported. + * A maximum of six POST requests can be pre-obtained. To prefetch the seventh post request, + * call API{@link clearPrefetchedResource} to clear the cache of unnecessary post requests. + * Otherwise, the cache of the earliest prefetched POST request will be automatically cleared. + * To use the prefetched resource cache, you need to add the key value ArkWebPostCacheKey to the header of the + * POST request. The content of the key value is the cacheKey of the corresponding cache. + * @param { RequestInfo } request - The information of the request. + * @param { Array } [additionalHeaders] - Additional HTTP request header of the request. + * @param { string } [cacheKey] - The key for memory cache. Default value is the url of the request. + * Only support number and letters. + * @param { int } [cacheValidTime] - The valid time of the cache for request, ranges greater than 0. + * The unit is second. Default value is 300s. + * The value of cacheValidTime must between 1 and 2147483647. + * @throws { BusinessError } 17100002 - URL error. The webpage corresponding to the URL is invalid, or the URL + * length exceeds 2*1024*1024. + * @syscap SystemCapability.Web.Webview.Core + * @atomicservice + * @since 22 dynamic&static + */ static prefetchResource(request: RequestInfo, additionalHeaders?: Array, cacheKey?: string, - cacheValidTime?: number): void; + cacheValidTime?: int): void; /** * Clears the cache of prefetched resources based on the specified cache key list. @@ -6297,6 +6357,16 @@ declare namespace webview { * @atomicservice * @since 12 */ + /** + * Warmup the registered service worker associated the url. + * @param { string } url - The url. + * @throws { BusinessError } 17100002 - URL error. The webpage corresponding to the URL is invalid, or the URL + * length exceeds 2*1024*1024. + * @static + * @syscap SystemCapability.Web.Webview.Core + * @atomicservice + * @since 22 dynamic&static + */ static warmupServiceWorker(url: string): void; /** @@ -6314,6 +6384,19 @@ declare namespace webview { * @syscap SystemCapability.Web.Webview.Core * @since 12 */ + /** + * Inject offline resources into cache. + * + * @param { Array } resourceMaps - Array of offline resource info maps. + * The count of array must between 1 and 30. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associated with a Web component. + * @throws { BusinessError } 17100002 - URL error. The webpage corresponding to the URL is invalid, or the URL + * length exceeds 2*1024*1024. + * @syscap SystemCapability.Web.Webview.Core + * @since 22 + * @arkts 1.1&1.2 + */ injectOfflineResources(resourceMaps: Array): void; /** -- Gitee