We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
MaterialsConsole

native_interface_arkweb.h

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

Overview

native_interface_arkweb.h is the core entry header file of ArkWeb Native API. It defines the enums, structs, and NDK function interfaces required for interaction between apps and the ArkWeb engine, covering features such as JavaScript execution and proxy injection, cookie management, blankless loading control, and kernel version selection. This module is suitable for scenarios that require deep interaction with the Web component through native methods. It addresses the technical challenge that complex capabilities of the ArkWeb component (such as JavaScript bidirectional communication, cookie persistence, and kernel version switching) cannot be directly called at the ArkTS layer, providing developers with complete low-level control to implement high-performance, customizable Web component features.

File to include: <web/native_interface_arkweb.h>

Library: libohweb.so

System capability: SystemCapability.Web.Webview.Core

Since: 11

Related module: Web

Summary

Structs

Expand
Name typedef Keyword Description
ArkWeb_BlanklessInfo ArkWeb_BlanklessInfo Defines the prediction information about blankless loading, including the first screen similarity, first screen loading duration, and error code. The application determines whether to enable frame insertion for blankless loading based on the prediction information.

Enums

Expand
Name typedef Keyword Description
ArkWebEngineVersion ArkWebEngineVersion ArkWeb kernel version. For details, see M114 Kernel Adaptation Guide on HarmonyOS 6.0, M132 Kernel Adaptation Guide on HarmonyOS 7.0.

Functions

Expand
Name typedef Keyword Description
typedef void (*NativeArkWeb_OnJavaScriptCallback)(const char*) NativeArkWeb_OnJavaScriptCallback Called to return the result after the JavaScript code is executed.
typedef char* (*NativeArkWeb_OnJavaScriptProxyCallback)(const char** argv, int32_t argc) NativeArkWeb_OnJavaScriptProxyCallback Called when a JavaScript proxy is registered.
typedef void (*NativeArkWeb_OnValidCallback)(const char*) NativeArkWeb_OnValidCallback Called when a Web component is valid.
typedef void (*NativeArkWeb_OnDestroyCallback)(const char*) NativeArkWeb_OnDestroyCallback Called when a Web component is destroyed.
typedef void (*OH_ArkWeb_OnCookieSaveCallback)(ArkWeb_ErrorCode errorCode) OH_ArkWeb_OnCookieSaveCallback

Defines the type of the callback function for saving cookies.

Since: 20

typedef void (*OH_ArkWeb_OnCookieFetchCallback)(ArkWeb_ErrorCode errorCode, char* cookieValue) OH_ArkWeb_OnCookieFetchCallback

Defines the type of the callback function invoked when the cookie fetch operation is complete.

Since: 26.0.0

void OH_NativeArkWeb_RunJavaScript(const char* webTag, const char* jsCode, NativeArkWeb_OnJavaScriptCallback callback) - Loads and asynchronously executes a JavaScript code in the current page.
void OH_NativeArkWeb_RegisterJavaScriptProxy(const char* webTag, const char* objName, const char** methodList, NativeArkWeb_OnJavaScriptProxyCallback* callback, int32_t size, bool needRefresh) - Registers an object and a list of function names.
void OH_NativeArkWeb_UnregisterJavaScriptProxy(const char* webTag, const char* objName) - Deletes a registered object and its callback.
void OH_NativeArkWeb_SetJavaScriptProxyValidCallback(const char* webTag, NativeArkWeb_OnValidCallback callback) - Sets a callback used when an object is valid.
NativeArkWeb_OnValidCallback OH_NativeArkWeb_GetJavaScriptProxyValidCallback(const char* webTag) - Obtains the callback used when a registered object is valid.
void OH_NativeArkWeb_SetDestroyCallback(const char* webTag, NativeArkWeb_OnDestroyCallback callback) - Sets the callback function invoked when the Web component is destroyed.
NativeArkWeb_OnDestroyCallback OH_NativeArkWeb_GetDestroyCallback(const char* webTag) - Obtains the registered callback function invoked when the Web component is destroyed.
ArkWeb_ErrorCode OH_NativeArkWeb_LoadData(const char* webTag,const char* data,const char* mimeType,const char* encoding,const char* baseUrl,const char* historyUrl) - Loads data or URLs. This function must be called in the main thread.
void OH_NativeArkWeb_RegisterAsyncThreadJavaScriptProxy(const char* webTag,const ArkWeb_ProxyObjectWithResult* proxyObject, const char* permission) - Registers a JavaScript object that contains callback methods, which can have return values. This object will be registered into all frames of the current page, including all iframes, and can be accessed by using the name specified in ArkWeb_ProxyObjectWithResult. The object takes effect in JavaScript only after the page is loaded or reloaded next time. Its methods are executed in the worker thread of ArkWeb.
ArkWeb_ErrorCode OH_ArkWebCookieManager_SaveCookieSync() -

Persists all cookies currently accessible through the CookieManager API to the disk. To use this API on a non-UI thread, initialize the CookieManager API using OH_ArkWeb_GetNativeAPI first.

Since: 20

void OH_ArkWebCookieManager_SaveCookieAsync(OH_ArkWeb_OnCookieSaveCallback callback) -

Persists all cookies currently accessible through the CookieManager API to the disk. Without initializing the CookieManager API, this API is automatically executed on the UI thread.

Since: 20

ArkWeb_BlanklessInfo OH_NativeArkWeb_GetBlanklessInfoWithKey(const char* webTag, const char* key) - Obtains the first screen loading prediction information, and starts to generate the loading transition frame. The application determines whether to enable blankless loading based on the information. For details, see ArkWeb_BlanklessInfo. This API must be used together with the OH_NativeArkWeb_SetBlanklessLoadingWithKey API and must be called before the page loading API is triggered and after WebViewController is bound to the Web component.
ArkWeb_BlanklessErrorCode OH_NativeArkWeb_SetBlanklessLoadingWithKey(const char* webTag, const char* key, bool isStarted) - Sets whether to enable blankless loading. This API must be used together with the OH_NativeArkWeb_GetBlanklessInfoWithKey API.
void OH_NativeArkWeb_ClearBlanklessLoadingCache(const char* key[], uint32_t size) - Clears the blankless loading cache of the page with a specified key value.
uint32_t OH_NativeArkWeb_SetBlanklessLoadingCacheCapacity(uint32_t capacity) - Sets the persistent cache capacity of the blankless loading solution and returns the value that takes effect. The default cache capacity is 30 MB, and the maximum cache capacity is 100 MB. When this limit is exceeded, transition frames that are not frequently used are eliminated.
void OH_NativeArkWeb_SetActiveWebEngineVersion(ArkWebEngineVersion webEngineVersion) - Sets the ArkWeb kernel version. If the system does not support the specified version, the setting does not take effect and the system default kernel is used (see Constraints). This API is a global static method and must be called before initializeWebEngine. If any Web component has already been loaded, the setting does not take effect.
ArkWebEngineVersion OH_NativeArkWeb_GetActiveWebEngineVersion() - Obtain the current ArkWeb kernel version.
bool OH_NativeArkWeb_IsActiveWebEngineEvergreen() - Checks whether the ArkWeb kernel used by the application is the evergreen kernel, that is, the latest kernel of the system.
void OH_NativeArkWeb_LazyInitializeWebEngineInCookieManager(bool lazy) - Sets whether to delay the initialization of the ArkWeb kernel. If this method is not called, the ArkWeb kernel is not delayed by default.
void OH_ArkWebCookieManager_FetchCookieAsync(const char* url, bool incognito, bool includeHttpOnly, bool includePartitionedCookies, OH_ArkWeb_OnCookieFetchCallback callback) -

Asynchronously obtains the cookies corresponding to the specified URL. Without initializing the CookieManager API, this API is automatically executed on the UI thread.

Since: 26.0.0

ArkWeb_ErrorCode OH_ArkWebCookieManager_FetchCookieSync(const char* url, bool incognito, bool includeHttpOnly, bool includePartitionedCookies, char** cookieValue) -

Obtains the cookies corresponding to the specified URL. To use this API on a non-UI thread, initialize the CookieManager API using OH_ArkWeb_GetNativeAPI first.

Since: 26.0.0

Enum Description

ArkWebEngineVersion

Phone20+PC/2in120+Tablet20+TV20+Wearable20+
enum ArkWebEngineVersion

Description

For ArkWeb kernel versions, see Adaptation Guide for the M114 Kernel on HarmonyOS 6.0 and Adaptation Guide for the M132 Kernel on HarmonyOS 7.0.

Expand
Kernel Type Name Description
Evergreen kernel EVERGREEN WebCore Latest Web kernel of the system, based on which the complete functionalities are implemented. This kernel is recommended for applications.
Legacy kernel LEGACY WebCore A previous-release kernel that receives only security and PR-related fixes, used solely for compatibility rollback, and is supported for a fixed duration only.

Since: 20

Expand
Enum Description
SYSTEM_DEFAULT = 0 System default kernel (see Constraints). The default kernel is M132 for HarmonyOS 6.0 and M144 for HarmonyOS 7.0.
ARKWEB_M114 = 1 Legacy kernel of HarmonyOS 6.0. Developers can select this legacy kernel. If this kernel does not exist on the system version, the setting does not take effect and the system default kernel is used.
ARKWEB_M132 = 2 Evergreen kernel of HarmonyOS 6.0 (legacy kernel of HarmonyOS 7.0). M132 is the default kernel of HarmonyOS 6.0. If this kernel does not exist on the system version, the setting does not take effect and the system default kernel is used.
ARKWEB_M144 = 3

Evergreen kernel of HarmonyOS 7.0. M144 is the default kernel of HarmonyOS 7.0. If this kernel does not exist on the system version, the setting does not take effect and the system default kernel is used.

Since: 26.0.0

ARKWEB_EVERGREEN = 99999

Evergreen kernel, the latest kernel of the system. Developers can select to use the latest kernel on each system version.

Since: 23

Function Description

NativeArkWeb_OnJavaScriptCallback()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
typedef void (*NativeArkWeb_OnJavaScriptCallback)(const char*)

Description

Called to return the result after the JavaScript code is executed.

Since: 11

NativeArkWeb_OnJavaScriptProxyCallback()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
typedef char* (*NativeArkWeb_OnJavaScriptProxyCallback)(const char** argv, int32_t argc)

Description

Called when a JavaScript proxy is registered.

Since: 11

NativeArkWeb_OnValidCallback()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
typedef void (*NativeArkWeb_OnValidCallback)(const char*)

Description

Called when a Web component is valid.

Since: 11

NativeArkWeb_OnDestroyCallback()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
typedef void (*NativeArkWeb_OnDestroyCallback)(const char*)

Description

Called when a Web component is destroyed.

Since: 11

OH_ArkWeb_OnCookieSaveCallback()

Phone20+PC/2in120+Tablet20+TV20+Wearable20+
typedef void (*OH_ArkWeb_OnCookieSaveCallback)(ArkWeb_ErrorCode errorCode)

Description

Called when cookies are saved.

Since: 20

Parameters

Expand
Name Description
ArkWeb_ErrorCode errorCode

ARKWEB_SUCCESS: The cookies are successfully saved.

ARKWEB_COOKIE_SAVE_FAILED: Failed to save the cookies.

ARKWEB_COOKIE_MANAGER_INITIALIZE_FAILED: The CookieManager initialization failed.

OH_ArkWeb_OnCookieFetchCallback()

Phone26.0.0+PC/2in126.0.0+Tablet26.0.0+TV26.0.0+Wearable26.0.0+
typedef void (*OH_ArkWeb_OnCookieFetchCallback)(ArkWeb_ErrorCode errorCode, char* cookieValue)

Description

Defines a pointer to the callback function invoked when the cookie fetch operation is complete.

Since: 26.0.0

Parameters

Expand
Name Description
ArkWeb_ErrorCode errorCode

Error code of the cookie fetch callback.

ARKWEB_SUCCESS: The cookies are fetched successfully.

ARKWEB_INVALID_URL: Invalid URL.

ARKWEB_LIBRARY_OPEN_FAILURE: Failed to open the dynamic link library.

ARKWEB_LIBRARY_SYMBOL_NOT_FOUND: The required symbol is not found in the dynamic link library.

char* cookieValue Cookies corresponding to the URL. The function allocates memory for cookieValue, and the developer must release the string through OH_ArkWeb_ReleaseString.

OH_NativeArkWeb_RunJavaScript()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
void OH_NativeArkWeb_RunJavaScript(const char* webTag, const char* jsCode, NativeArkWeb_OnJavaScriptCallback callback)

Description

Loads and asynchronously executes a piece of JavaScript code in the context of the current page. This function must be called in the main thread. Use case: Used when you need to dynamically modify page content, obtain page runtime information, or interact with page JavaScript at the native layer, for example, obtaining form data or executing custom scripts.

System capability: SystemCapability.Web.Webview.Core

Since: 11

Parameters

Expand
Name Description
const char* webTag Name of the Web component.
const char* jsCode A piece of JavaScript code script.
NativeArkWeb_OnJavaScriptCallback callback Callback for notifying the code execution result.

OH_NativeArkWeb_RegisterJavaScriptProxy()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
void OH_NativeArkWeb_RegisterJavaScriptProxy(const char* webTag, const char* objName, const char** methodList, NativeArkWeb_OnJavaScriptProxyCallback* callback, int32_t size, bool needRefresh)

Description

Registers a list of object and function names, used to inject native objects into web pages and implement bidirectional communication between the app side and the frontend page. This is used in scenarios such as web pages calling native functions, native code controlling web page behavior, and cross-layer interaction in hybrid apps.

System capability: SystemCapability.Web.Webview.Core

Since: 11

Parameters

Expand
Name Description
const char* webTag Name of the Web component.
const char* objName Name of the registered object.
const char** methodList Name of the registered method list.
NativeArkWeb_OnJavaScriptProxyCallback* callback Registered callback.
int32_t size Number of registered callbacks.
bool needRefresh Whether a page need to be refreshed. The value true indicates that the page needs to be refreshed, and false indicates the opposite.

OH_NativeArkWeb_UnregisterJavaScriptProxy()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
void OH_NativeArkWeb_UnregisterJavaScriptProxy(const char* webTag, const char* objName)

Description

Deletes a registered object and its callback functions, used to clean up JavaScript injection objects that are no longer needed. Typical use cases: cleaning up injected objects when a page is destroyed, removing corresponding native interfaces when a function module is unloaded, and preventing memory leaks.

System capability: SystemCapability.Web.Webview.Core

Since: 11

Parameters

Expand
Name Description
const char* webTag Name of the Web component.
const char* objName Name of the registered object.

OH_NativeArkWeb_SetJavaScriptProxyValidCallback()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
void OH_NativeArkWeb_SetJavaScriptProxyValidCallback(const char* webTag, NativeArkWeb_OnValidCallback callback)

Description

Sets the callback invoked when an object can be registered. Used when specific logic needs to be executed after a JavaScript proxy object is successfully registered, for example, notifying the page or logging after successful registration.

System capability: SystemCapability.Web.Webview.Core

Since: 11

Parameters

Expand
Name Description
const char* webTag Name of the Web component.
NativeArkWeb_OnValidCallback callback Callback used when an object is valid.

OH_NativeArkWeb_GetJavaScriptProxyValidCallback()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
NativeArkWeb_OnValidCallback OH_NativeArkWeb_GetJavaScriptProxyValidCallback(const char* webTag)

Description

Obtains the callback used when a registered object is valid.

System capability: SystemCapability.Web.Webview.Core

Since: 11

Parameters

Expand
Name Description
const char* webTag Name of the Web component.

Returns

Expand
Type Description
NativeArkWeb_OnValidCallback Callback used when a registered object is valid. If no valid callback function is set for the webTag parameter, a null pointer is returned.

OH_NativeArkWeb_SetDestroyCallback()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
void OH_NativeArkWeb_SetDestroyCallback(const char* webTag, NativeArkWeb_OnDestroyCallback callback)

Description

Sets the callback invoked when the Web component is destroyed. Typical use cases: releasing resources, cleaning up states, or performing finalization operations when the Web component is destroyed, for example, releasing JavaScript proxy objects, canceling network requests, or closing file handles.

System capability: SystemCapability.Web.Webview.Core

Since: 11

Parameters

Expand
Name Description
const char* webTag Name of the Web component.
NativeArkWeb_OnDestroyCallback callback Callback invoked when the Web component is destroyed.

OH_NativeArkWeb_GetDestroyCallback()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
NativeArkWeb_OnDestroyCallback OH_NativeArkWeb_GetDestroyCallback(const char* webTag)

Description

Obtains the registered callback invoked when the Web component is destroyed.

System capability: SystemCapability.Web.Webview.Core

Since: 11

Parameters

Expand
Name Description
const char* webTag Name of the Web component.

Returns

Expand
Type Description
NativeArkWeb_OnDestroyCallback Returns the registered callback for when the Web component is destroyed. If the destroy callback specified by the webTag parameter is not set, a null pointer is returned.

OH_NativeArkWeb_LoadData()

Phone15+PC/2in115+Tablet15+TV19+Wearable18+
ArkWeb_ErrorCode OH_NativeArkWeb_LoadData(const char* webTag, const char* data, const char* mimeType, const char* encoding, const char* baseUrl, const char* historyUrl)

Description

Loads data or a URL. This function must be called in the main thread. Typical use cases: loading page content from the network or local files, dynamically generating and displaying HTML content, implementing offline page display, and custom page rendering.

System capability: SystemCapability.Web.Webview.Core

Since: 15

Parameters

Expand
Name Description
const char* webTag Name of the Web component.
const char* data String being base64 or URL encoded, which cannot be empty.
const char* mimeType Media type, such as text/html, which cannot be empty.
const char* encoding Encoding type, such as UTF-8, which cannot be empty.
const char* baseUrl Specified URL path (using the "http", "https", or "data" protocol), assigned to window.origin by the Web component.
const char* historyUrl Historical URL. If this parameter is not empty, it can be managed in historical records to implement backward and forward navigation.

Returns

Expand
Type Description
ArkWeb_ErrorCode

Error codes of OH_NativeArkWeb_LoadData.

ARKWEB_SUCCESS: data loaded successfully.

ARKWEB_INVALID_PARAM: a required parameter is not specified, the parameter type is incorrect, or parameter verification fails.

ARKWEB_INIT_ERROR: initialization fails. No valid Web component is found based on the passed "webTag".

ARKWEB_LIBRARY_OPEN_FAILURE: failed to open the dynamic link library. Check whether the library file path is correct, whether the library file is corrupted, and whether you have sufficient access permissions.

ARKWEB_LIBRARY_SYMBOL_NOT_FOUND: the required symbol is not found in the dynamic link library.

OH_NativeArkWeb_RegisterAsyncThreadJavaScriptProxy()

Phone20+PC/2in120+Tablet20+TV20+Wearable20+
void OH_NativeArkWeb_RegisterAsyncThreadJavaScriptProxy(const char* webTag, const ArkWeb_ProxyObjectWithResult* proxyObject, const char* permission)

Description

Registers a JavaScript object that contains callback methods with return values. The object is injected into all frames of the current page, including all iframes, and can be accessed by the name specified in ArkWeb_ProxyObjectWithResult. The object takes effect in JavaScript only after the next page load or reload. These methods are executed in the worker thread of ArkWeb. Typical use cases: processing JavaScript calls and returning results in the worker thread, for example, performing time-consuming computations, asynchronous task processing, and complex business logic processing, to avoid blocking the main thread.

Since: 20

Parameters

Expand
Name Description
const char* webTag Name of the Web component.
const ArkWeb_ProxyObjectWithResult* proxyObject Object to be registered.
const char* permission A JSON string used to configure the object and method levels of the JSBridge permission. This value is empty by default.

OH_ArkWebCookieManager_SaveCookieSync()

Phone20+PC/2in120+Tablet20+TV20+Wearable20+
ArkWeb_ErrorCode OH_ArkWebCookieManager_SaveCookieSync()

Description

Persists all cookies currently accessible through the CookieManager API to the disk. If this API is used in a non-UI thread, you need to initialize the CookieManager API using OH_ArkWeb_GetNativeAPI first. Typical use cases: saving cookie states when the app exits or at specific times, for example, saving user login states, app configuration information, and session data, to ensure that the previous state can be restored after the app restarts.

Since: 20

Returns

Expand
Type Description
ArkWeb_ErrorCode

Error codes of OH_ArkWebCookieManager_SaveCookieSync. Check whether the disk space is sufficient, whether write permission is available, and whether the cookie data format is correct.

ARKWEB_SUCCESS: the cookie is saved successfully.

ARKWEB_COOKIE_SAVE_FAILED: failed to save the cookie.

ARKWEB_COOKIE_MANAGER_INITIALIZE_FAILED: failed to initialize CookieManager.

ARKWEB_COOKIE_MANAGER_NOT_INITIALIZED: on a non-UI thread, calling this API without initializing the CookieManager API is not allowed. Use OH_ArkWeb_GetNativeAPI to initialize the CookieManager API first.

OH_ArkWebCookieManager_SaveCookieAsync()

Phone20+PC/2in120+Tablet20+TV20+Wearable20+
void OH_ArkWebCookieManager_SaveCookieAsync(OH_ArkWeb_OnCookieSaveCallback callback)

Description

Persists all cookies currently accessible through the CookieManager API to the disk. If this API is used in a non-UI thread, you need to initialize the CookieManager API using OH_ArkWeb_GetNativeAPI first. Without initializing the CookieManager API, this API is automatically executed on the UI thread. Typical use cases: asynchronously saving cookie states, for example, saving cookies asynchronously after page loading is complete or after a user operation, to avoid blocking the main thread.

Since: 20

Parameters

Expand
Name Description
OH_ArkWeb_OnCookieSaveCallback callback Callback invoked after the cookie is saved successfully or fails. When a callback is passed in, the operation result is received asynchronously using the callback, which is suitable for scenarios requiring asynchronous notification of the save result. When no callback is passed in, the behavior may vary depending on the specific implementation.

OH_NativeArkWeb_GetBlanklessInfoWithKey()

Phone20+
ArkWeb_BlanklessInfo OH_NativeArkWeb_GetBlanklessInfoWithKey(const char* webTag, const char* key)

Description

Obtains the first screen loading prediction information, and starts to generate the loading transition frame. The application determines whether to enable blankless loading based on the information. For details, see ArkWeb_BlanklessInfo. This API must be used together with the OH_NativeArkWeb_SetBlanklessLoadingWithKey API and must be called before the page loading API is triggered and after WebViewController is bound to the Web component.

NOTE
  • The default size of the persistent cache capacity is 30 MB (about 30 pages). You can set the cache capacity by calling OH_NativeArkWeb_SetBlanklessLoadingCacheCapacity. For details, see the description of this API. When the maximum capacity is exceeded, the cache is updated based on the Least Recently Used (LRU) mechanism. The persistent cache data that has been stored for more than seven days is automatically cleared. After the cache is cleared, the optimization effect appears when the page is loaded for the third time.
  • If the value of similarity in ArkWeb_BlanklessInfo is extremely low, check whether the key value is correctly passed.
  • After this API is called, page loading snapshot detection and transition frame generation calculation are enabled, which generates certain resource overhead.
  • Blankless loading consumes resources, which depends on the resolution of the Web component. It is assumed that a width and a height of the resolution are respectively w and h. When a page is opened, the peak memory usage increases by about 12×w×h B. After the page is opened, the memory is reclaimed, which does not affect the stable memory usage. When the size of the solid-state application cache is increased, the increased cache of each page is about w×h/10 B and the cache is located in the application cache.

Required permissions: ohos.permission.INTERNET and ohos.permission.GET_NETWORK_INFO

Since: 20

Device behavior differences: This API can be called on phones. For other device types, error code 801 is returned.

Parameters

Expand
Name Description
const char* webTag Name of the Web component.
const char* key

Key value that uniquely identifies the page.

The value cannot be empty and can contain a maximum of 2048 characters.

Invalid values do not take effect.

Returns

Expand
Type Description
ArkWeb_BlanklessInfo Prediction information about blankless loading, including the first screen similarity and first screen loading duration. The application determines whether to enable blankless loading based on the prediction information.

OH_NativeArkWeb_SetBlanklessLoadingWithKey()

Phone20+
ArkWeb_BlanklessErrorCode OH_NativeArkWeb_SetBlanklessLoadingWithKey(const char* webTag, const char* key, bool isStarted)

Description

Sets whether blankless loading is enabled. This API must be used together with OH_NativeArkWeb_GetBlanklessInfoWithKey.

Usage scenario

Used when dynamically deciding whether to enable blankless loading based on the predicted information of the first screen loading of the page, for example, enabling blankless loading optimization when the similarity prediction value is high, and disabling it when the similarity is low to avoid resource waste.

NOTE
  • This API must be called after the page loading API is triggered. Other constraints are the same as those of OH_NativeArkWeb_GetBlanklessInfoWithKey.
  • The page must be loaded in the component that calls this set of APIs.
  • When the similarity is low, the system will deem the scene change too abrupt and frame insertion will fail.

Required permissions: ohos.permission.INTERNET and ohos.permission.GET_NETWORK_INFO

Since: 20

Parameters

Expand
Name Description
const char* webTag Name of the Web component.
const char* key

Unique key that identifies this page. It must be the same as the key value of the OH_NativeArkWeb_GetBlanklessInfoWithKey API.

Valid value range: non-empty, with a maximum length of 2048 characters.

Behavior for invalid values: returns the error code ArkWeb_BlanklessErrorCode, and frame insertion does not take effect.

bool isStarted

Whether to enable frame insertion. The value true means to enable frame insertion. Select this option when the first screen of the page has high similarity and the blank screen time needs to be reduced to improve the loading experience. The value false means to disable frame insertion. Select this option when the page transition is too large, resulting in low similarity, or when the loading experience does not need to be optimized.

Default value: false.

Returns

Expand
Type Description
ArkWeb_BlanklessErrorCode Enumerates the error codes. For details, see ArkWeb_BlanklessErrorCode.

OH_NativeArkWeb_ClearBlanklessLoadingCache()

Phone20+
void OH_NativeArkWeb_ClearBlanklessLoadingCache(const char* key[], uint32_t size)

Description

Clears the blankless loading cache of the page with a specified key value.

In an applet or web application, when the content changes significantly during page loading, an obvious scene change may occur. If you are concerned about this change, you can use this API to clear the page cache.

NOTE
  • After the page is cleared, the optimization effect appears when the page is loaded for the third time.

Since: 20

Parameters

Expand
Name Description
const char* key[]

List of key values for clearing Blankless optimization pages. The key values are those specified in OH_NativeArkWeb_GetBlanklessInfoWithKey.

Valid value range: the length does not exceed 2048, and the keys array length is less than or equal to 100. The key is the same as the one input to ArkWeb when loading the page.

Behavior for invalid values: if the key length exceeds 2048, the key does not take effect; if the length exceeds 100, the first 100 keys are used; if NULL, all caches are cleared.

uint32_t size

Size of the keys array.

Valid value range: 0 to 100. If the value exceeds 100, the first 100 keys in the array are used.

Behavior for invalid values: if the value is greater than 100, the first 100 keys are used.

OH_NativeArkWeb_SetBlanklessLoadingCacheCapacity()

Phone20+
uint32_t OH_NativeArkWeb_SetBlanklessLoadingCacheCapacity(uint32_t capacity)

Description

Sets the persistent cache capacity for the blankless loading solution and returns the actual effective value. The default cache capacity is 30 MB, and the maximum value is 100 MB. When the actual cache exceeds the capacity, infrequently used transition frames are evicted for cleanup. Typical use cases: adjusting the cache size based on the app memory usage, optimizing storage space usage, and balancing the blankless effect with system resource consumption.

Usage scenario

Scenarios where the user needs to customize the cache capacity.

Since: 20

Parameters

Expand
Name Description
uint32_t capacity

Sets the persistent cache capacity, in MB. The maximum value cannot exceed 100 MB.

Default value: 30 MB.

Valid range: 0 to 100. When set to 0, there is no cache space and the feature is globally disabled.

Invalid value handling: When the value is greater than 100, the effective value is 100.

Returns

Expand
Type Description
uint32_t

Effective capacity value, in MB, ranging from 0 to 100.

If the value is greater than 100, the effective value is 100.

OH_NativeArkWeb_SetActiveWebEngineVersion()

Phone20+PC/2in120+Tablet20+TV20+Wearable20+
void OH_NativeArkWeb_SetActiveWebEngineVersion(ArkWebEngineVersion webEngineVersion)

Description

Sets the ArkWeb kernel version. If the system does not support the specified version, the setting is invalid and the system default kernel is used (see Constraints). Used when a specific kernel version needs to be selected based on app compatibility requirements, for example, when an app depends on features of an older kernel version or needs to maintain compatibility on a newer system version, a specific legacy kernel version can be specified.

This API is a global static method and must be called before initializeWebEngine is called. If any Web component has been loaded, the setting of this API is invalid.

Legacy kernel adaptation

Since HarmonyOS 6.0, some ArkWeb APIs do not take effect when the legacy kernel is used. For details, see Adaptation Guide for the M114 Kernel on HarmonyOS 6.0 and Adaptation Guide for the M132 Kernel on HarmonyOS 7.0.

Since: 20

Parameters

Expand
Name Description
ArkWebEngineVersion webEngineVersion ArkWeb kernel version. For details, see ArkWebEngineVersion.

OH_NativeArkWeb_GetActiveWebEngineVersion()

Phone20+PC/2in120+Tablet20+TV20+Wearable20+
ArkWebEngineVersion OH_NativeArkWeb_GetActiveWebEngineVersion()

Description

Obtains the current ArkWeb kernel version.

Since: 20

Returns

Expand
Type Description
ArkWebEngineVersion The current ArkWeb kernel version defined by ArkWebEngineVersion.

OH_NativeArkWeb_IsActiveWebEngineEvergreen()

Phone23+PC/2in123+Tablet23+TV23+Wearable23+
bool OH_NativeArkWeb_IsActiveWebEngineEvergreen()

Description

Checks whether the ArkWeb kernel used by the application is the evergreen kernel, that is, the latest kernel of the system.

Since: 23

Returns

Expand
Type Description
bool Whether the kernel used by the current app is the Evergreen kernel. The value true indicates it is the Evergreen kernel, and false indicates it is not.

OH_NativeArkWeb_LazyInitializeWebEngineInCookieManager()

Phone22+PC/2in122+Tablet22+TV22+Wearable22+
void OH_NativeArkWeb_LazyInitializeWebEngineInCookieManager(bool lazy)

Description

Sets whether to defer the initialization of the ArkWeb kernel. If this method is not called, the ArkWeb kernel is not deferred for initialization by default. Typical use cases: the Web function is not needed immediately at app startup, and you want to delay kernel initialization to save startup resources; the app only needs to use CookieManager without Web component rendering for the time being. This API is a global static method and must be called before using the Web component and initializing the ArkWeb kernel; otherwise, the setting is invalid.

NOTE
  • This API is a global static method and must be called before using the ArkWeb component and initializing the ArkWeb kernel; otherwise, the setting is invalid.
  • This API applies only to APIs that initialize CookieManager when called, such as those in the ArkWeb_CookieManagerAPI module. After this API is called, calling the applicable APIs skips the initialization of the ArkWeb kernel when initializing CookieManager, and you need to initialize the ArkWeb kernel later.

Since: 22

Parameters

Expand
Name Description
bool lazy Whether to delay the initialization of the ArkWeb kernel. The value true means to delay the initialization, and false means the opposite.

OH_ArkWebCookieManager_FetchCookieAsync()

Phone26.0.0+PC/2in126.0.0+Tablet26.0.0+TV26.0.0+Wearable26.0.0+
void OH_ArkWebCookieManager_FetchCookieAsync(const char* url, bool incognito, bool includeHttpOnly, bool includePartitionedCookies, OH_ArkWeb_OnCookieFetchCallback callback)

Description

Asynchronously obtains the cookies corresponding to the specified URL. Without initializing the CookieManager API, this API is automatically executed on the UI thread.

Since: 26.0.0

Parameters

Expand
Name Description
const char* url Specifies the URL to which the cookies belong. It is recommended to provide the complete URL.
bool incognito true indicates fetching the in-memory cookies of the webview in private mode, and false indicates fetching the cookies in non-private mode.
bool includeHttpOnly Whether cookies marked with the HTTP-Only attribute are included in cookieValue. true indicates included, and false indicates not included.
bool includePartitionedCookies Whether cookies marked with the Partitioned attribute are included in cookieValue. true indicates included, and false indicates not included.
OH_ArkWeb_OnCookieFetchCallback callback Executes this callback after the cookies are fetched.

OH_ArkWebCookieManager_FetchCookieSync()

Phone26.0.0+PC/2in126.0.0+Tablet26.0.0+TV26.0.0+Wearable26.0.0+
ArkWeb_ErrorCode OH_ArkWebCookieManager_FetchCookieSync(const char* url, bool incognito, bool includeHttpOnly, bool includePartitionedCookies, char** cookieValue)

Description

Obtains the cookies corresponding to the specified URL. If this API is used in a non-UI thread, you need to initialize the CookieManager API using OH_ArkWeb_GetNativeAPI first.

Since: 26.0.0

Parameters

Expand
Name Description
const char* url Specifies the URL to which the cookies belong. It is recommended to provide the complete URL.
bool incognito true indicates obtaining the in-memory cookies of the webview in incognito mode, and false indicates obtaining the cookies in non-incognito mode.
bool includeHttpOnly Whether cookies marked with the HTTP-Only attribute are included in cookieValue. true indicates included, and false indicates not included.
bool includePartitionedCookies Whether cookies marked with the Partitioned attribute are included in cookieValue. true indicates included, and false indicates not included.
char** cookieValue Obtains the cookies corresponding to the URL. The function allocates memory for cookieValue, and the developer must release the string through OH_ArkWeb_ReleaseString.

Return value

Expand
Type Description
ArkWeb_ErrorCode errorCode

Error code of the return value.

ARKWEB_SUCCESS Cookies obtained successfully.

ARKWEB_INVALID_URL Invalid URL.

ARKWEB_INVALID_PARAM Invalid parameter.

ARKWEB_COOKIE_MANAGER_NOT_INITIALIZED On a non-UI thread, calling this interface without initializing the CookieManager interface is not allowed. First use OH_ArkWeb_GetNativeAPI to initialize the CookieManager interface.

ARKWEB_LIBRARY_OPEN_FAILURE Failed to open the dynamic link library.

ARKWEB_LIBRARY_SYMBOL_NOT_FOUND The required symbol is not found in the dynamic link library.