openharmony 鸿蒙 capi-web-arkweb-controllerapi

2026-08-25 浏览 (1)

ArkWeb_ControllerAPI

typedef struct {...} ArkWeb_ControllerAPI

Overview

Defines a native controller API. Before calling this API, you are advised to use ARKWEB_MEMBER_MISSING to check whether the function struct has the corresponding pointer to avoid crash caused by mismatch between the SDK and the device ROM. The controller APIs must be called on the UI thread through OH_ArkWeb_GetNativeAPI.

Since: 12

Related module: Web

Header file: arkweb_type.h

Summary

Member Variables

NameDescription
size_t sizeSize of the struct.

Member Functions

NameDescription
void (*runJavaScript)(const char* webTag, const ArkWeb_JavaScriptObject* javascriptObject)Injects a JavaScript script.
void (*registerJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject)Injects a JavaScript object with the window. Synchronous APIs of this object can then be invoked in the window.
void (*deleteJavaScriptRegister)(const char* webTag, const char* objName)Deletes a specific application JavaScript object that is registered with the window using registerJavaScriptProxy.
void (*refresh)(const char* webTag)Refreshes the web page. The page stack is cleared during the refresh. As a result, the current page cannot be navigated forward or backward.
void (*registerAsyncJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject)Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window.
ArkWeb_WebMessagePortPtr* (*createWebMessagePorts)(const char* webTag, size_t* size)Creates a post message port.
void (*destroyWebMessagePorts)(ArkWeb_WebMessagePortPtr** ports, size_t size)Destroys a message port.
ArkWeb_ErrorCode (*postWebMessage)(const char* webTag, const char* name, ArkWeb_WebMessagePortPtr* webMessagePorts, size_t size, const char* url)Sends a message port to the HTML page.
const char* (*getLastJavascriptProxyCallingFrameUrl)()Obtains the URL of the last frame that calls JavaScriptProxy. This function is invoked on the thread invoked by JavaScriptProxy. You can use registerJavaScriptProxy or JavaScriptProxy to inject a JavaScript object to a window object. This API can be used to obtain the URL of the last frame calls the injected object. You need to save the URL obtained from the invoked function.
Since: 14
void (*registerJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObjectWithResult* proxyObject,const char* permission)Injects a JavaScript object with the window. Synchronous APIs of this object can then be invoked in the window. The synchronization method of this object can contain return values.
Since: 18
void (*registerAsyncJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObject* proxyObject,const char* permission)Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window.
Since: 18

Member Function Description

runJavaScript()

void (*runJavaScript)(const char* webTag, const ArkWeb_JavaScriptObject* javascriptObject)

Description

Injects a JavaScript script.

Parameters

NameDescription
const char* webTagName of the Web component.
const ArkWeb_JavaScriptObject* javascriptObjectJavaScript object to inject.

registerJavaScriptProxy()

void (*registerJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject)

Description

Injects a JavaScript object with the window. Synchronous APIs of this object can then be invoked in the window.

Parameters

NameDescription
const char* webTagName of the Web component.
const ArkWeb_ProxyObject* proxyObjectObject to be registered.

deleteJavaScriptRegister()

void (*deleteJavaScriptRegister)(const char* webTag, const char* objName)

Description

Deletes a specific application JavaScript object that is registered with the window using registerJavaScriptProxy.

Parameters

NameDescription
const char* webTagName of the Web component.
const char* objNameName of the JavaScript object.

refresh()

void (*refresh)(const char* webTag)

Description

Refreshes the web page. The page stack is cleared during the refresh. As a result, the current page cannot be navigated forward or backward.

Parameters

NameDescription
const char* webTagName of the Web component.

registerAsyncJavaScriptProxy()

void (*registerAsyncJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject)

Description

Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window.

Parameters

NameDescription
const char* webTagName of the Web component.
const ArkWeb_ProxyObject* proxyObjectObject to be registered.

createWebMessagePorts()

ArkWeb_WebMessagePortPtr* (*createWebMessagePorts)(const char* webTag, size_t* size)

Description

Creates a post message port.

Parameters

NameDescription
const char* webTagName of the Web component.
size_t* sizeNumber of ports, which is an output parameter.

Returns

TypeDescription
ArkWeb_WebMessagePortPtrPointer to the message port.

destroyWebMessagePorts()

void (*destroyWebMessagePorts)(ArkWeb_WebMessagePortPtr** ports, size_t size)

Description

Destroys a message port.

Parameters

NameDescription
ArkWeb_WebMessagePortPtr** portsDouble pointer to the message port struct.
size_t sizeNumber of ports.

postWebMessage()

ArkWeb_ErrorCode (*postWebMessage)(const char* webTag, const char* name, ArkWeb_WebMessagePortPtr* webMessagePorts, size_t size, const char* url)

Description

Sends a message port to the HTML page.

Parameters

NameDescription
const char* webTagName of the Web component.
const char* nameName of the message sent to the HTML page.
ArkWeb_WebMessagePortPtr* webMessagePortsPointer to the message port.
size_t sizeNumber of ports.
const char* urlURL of the page that receives the message.

Returns

TypeDescription
Error codeARKWEB_SUCCESS: The operation is successful.
ARKWEB_INVALID_PARAM: The parameter is invalid.
ARKWEB_INIT_ERROR: The initialization fails because the Web component bound to webTag is not found.

getLastJavascriptProxyCallingFrameUrl()

const char* (*getLastJavascriptProxyCallingFrameUrl)()

Description

Obtains the URL of the last frame that calls JavaScriptProxy. This function is invoked on the thread invoked by JavaScriptProxy. You can use registerJavaScriptProxy or JavaScriptProxy to inject a JavaScript object to a window object. This API can be used to obtain the URL of the last frame calls the injected object. You need to save the URL obtained from the invoked function.

Since: 14

Returns

TypeDescription
const char*URL of the last frame that calls JavaScriptProxy.

registerJavaScriptProxyEx()

void (*registerJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObjectWithResult* proxyObject,const char* permission)

Description

Injects a JavaScript object with the window. Synchronous APIs of this object can then be invoked in the window. The synchronization method of this object can contain return values.

Since: 18

Parameters

NameDescription
const char* webTagName of the Web component.
const ArkWeb_ProxyObjectWithResult* proxyObjectObject to be registered.
const char* permissionA JSON string used to configure the object and method levels of the JSBridge permission. This value is empty by default.

registerAsyncJavaScriptProxyEx()

void (*registerAsyncJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObject* proxyObject, const char* permission)

Description

Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window.

Since: 18

Parameters

NameDescription
const char* webTagName of the Web component.
const ArkWeb_ProxyObject* proxyObjectObject to be registered.
const char* permissionA JSON string used to configure the object and method levels of the JSBridge permission. This value is empty by default.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 arkts-apis-webview-WebviewController

openharmony 鸿蒙 arkts-apis-webview-t

openharmony 鸿蒙 arkts-apis-webview

openharmony 鸿蒙 capi-arkweb-type-h

openharmony 鸿蒙 arkts-basic-components-web-FullScreenExitHandler

openharmony 鸿蒙 arkts-apis-webview-WebDownloadManager

openharmony 鸿蒙 arkts-basic-components-web-VerifyPinHandler

openharmony 鸿蒙 capi-web-arkweb-webmessage8h

openharmony 鸿蒙 arkts-apis-webview-NativeMediaPlayerHandler

openharmony 鸿蒙 capi-web-arkweb-proxymethodwithresult

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/OitBwrZX