openharmony 鸿蒙 arkts-apis-web-webNativeMessagingExtensionAbility

2026-08-25 浏览 (1)

@ohos.web.WebNativeMessagingExtensionAbility (Web Native Messaging Extension Ability)

WebNativeMessagingExtensionAbility provides the web native messaging capability and is inherited from ExtensionAbility.

NOTE

The initial APIs of this module are supported since API version 21. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { WebNativeMessagingExtensionAbility } from '@kit.ArkWeb';

WebNativeMessagingExtensionAbility

Provides the web native messaging capability and is inherited from ExtensionAbility.

Attributes

System capability: SystemCapability.Web.Webview.Core

Model restriction: This API can be used only in the stage model.

NameTypeRead-OnlyOptionalDescription
contextWebNativeMessagingExtensionContextNoNoContext of web native messaging.

onConnectNative

onConnectNative(info: ConnectionInfo): void

Called when a web native messaging connection is established.

System capability: SystemCapability.Web.Webview.Core

Model restriction: This API can be used only in the stage model.

Parameters

NameTypeMandatoryDescription
infoConnectionInfoYesConnection information.

Example

import { WebNativeMessagingExtensionAbility, ConnectionInfo } from '@kit.ArkWeb';

export class MyWebNativeMessagingExtension extends WebNativeMessagingExtensionAbility {
  onConnectNative(info: ConnectionInfo): void {
    console.info('Web Native connection established!');
    console.info(`Connection ID: ${info.connectionId}`);
    console.info(`Caller bundle: ${info.bundleName}`);
    // Process the service logic after the connection is established.
  }
}

onDisconnectNative

onDisconnectNative(info: ConnectionInfo): void

Called when a web native messaging connection is disconnected.

System capability: SystemCapability.Web.Webview.Core

Model restriction: This API can be used only in the stage model.

Parameters

NameTypeMandatoryDescription
infoConnectionInfoYesConnection information.

Example

import { WebNativeMessagingExtensionAbility, ConnectionInfo } from '@kit.ArkWeb';

export class MyWebNativeMessagingExtension extends WebNativeMessagingExtensionAbility {
  onDisconnectNative(info: ConnectionInfo): void {
    console.info('Web Native connection closed!');
    console.info(`Connection ID: ${info.connectionId}`);
    // Process the cleanup after the connection is disconnected.
  }
}

onDestroy

onDestroy(): void

Called when the WebNativeMessagingExtensionAbility is destroyed.

System capability: SystemCapability.Web.Webview.Core

Model restriction: This API can be used only in the stage model.

Example

import { WebNativeMessagingExtensionAbility } from '@kit.ArkWeb';

export class MyWebNativeMessagingExtension extends WebNativeMessagingExtensionAbility {
  onDestroy(): void {
    console.info('WebNativeMessagingExtensionAbility is about to be destroyed!');
    // Release resources or perform cleanup operations.
  }
}

ConnectionInfo

Represents the information object of the web native messaging connection.

System capability: SystemCapability.Web.Webview.Core

NameTypeRead-OnlyOptionalDescription
connectionIdnumberNoNoConnection ID.
bundleNamestringNoNoApplication bundle name of the caller.
extensionOriginstringNoNoOriginal URL of the caller extension.
fdReadnumberNoNoPipe file descriptor used to read data.
fdWritenumberNoNoPipe file descriptor used to write data.

你可能感兴趣的鸿蒙文章

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/sYn2YtKc