subscribeMessage
Registers a handler for a specified debugging message type to receive and process messages of that type.
It works with the sendMessage method to enable two-way communication with the message sender (e.g., the DevTool Desktop Application).
Syntax
iOS
LynxBaseInspectorOwnerNG.h
Android
LynxBaseInspectorOwnerNG.java
Harmony
LynxBaseInspectorOwner.ets
Parameters
type: The type of message to subscribe to, such as CDP or other custom message types.handler: An object that implementsMessageHandlerto receive debugging messages.
Warning
DevTool only holds a weak reference to the MessageHandler object. Developers need to manage its lifecycle.
Usage Example
Implementation Steps
- Implement
MessageHandlerto process incoming debugging messages. - Get the
LynxBaseInspectorOwnerinstance. On iOS and Android, it needs to be cast to theLynxBaseInspectorOwnerNGtype. - Call the
subscribeMessagemethod to subscribe to debugging messages of the specified type.
Code Example
The following example code subscribes to CDP messages. When a Page.enable message is received, it sends a Log.entryAdded message with the content Hello, Lynx DevTool!.
As a result, this log will be displayed in the Console panel of the DevTool Desktop Application.
iOS
TestMessageHandler.h
TestMessageHandler.m
ViewController.m
Android
TestMessageHandler.java
MainActivity.java
Harmony
TestMessageHandler.ets
Index.ets
Compatibility
LCD tables only load in the browser