目录

Running and Debugging an Atomic Service

To verify how an atomic service looks and behaves, you can run and debug it.

Running an Atomic Service on a Local Real Device

The procedure for running a HarmonyOS atomic service on a phone is the same as that on a tablet. You can use either USB or wireless debugging for connection.

For details, see Running Your App on a Local Real Device.

Running an Atomic Service on the Emulator

DevEco Studio includes the Emulator that mimics the essential features of real devices. This tool allows you to work more flexibly and efficiently when developing and debugging your atomic service, ultimately improving the overall development experience and productivity.

For details, see Running Your App on the Emulator.

Debugging with Hot Reload

Hot reload allows code changes to take effect in real time. After this feature is enabled in DevEco Studio, the debug device will automatically apply changes upon modification of page files (CSS, HXML, JS, or JSON) without additional steps. This significantly reduces recompilation and execution time while delivering a dramatic boost to development efficiency.

You can also use the ASCF CLI tool to enable hot reload. For details, see Enabling Hot Reload.

[h2]Environment Requirements

The following conditions should be met to use hot reload:

[h2]Enabling Hot Reload

  1. Connect to a device and select the device where the atomic service is running in DevEco Studio.

  2. Select an entry with from the run/debug configuration menu to enter the hot reload mode.

  3. Click to enable hot reloading. Wait until hot reload is enabled.

  4. Modify and save the CSS, HXML, JS, and JSON files and view the effects on the device in real time.

  5. Click to disable hot reload.

Debugging and Running ASCF Source Code

ASCF runtime includes the view layer (Webview) and the logic layer (V8 engine), with both supporting local debugging.

[h2]Using the ASCF Debugger

The ASCF Plugin version must be 1.0.4.304 or later.

For versions earlier than DevEco Studio 6.0, the debugging page is opened in the browser.

  1. Open the debugging page via View > Tool Windows > ASCF Debugger, or directly click in the bottom-left tool window bar (new UI only). For DevEco Studio versions earlier than 6.0.0, you can click in the tool window bar at the bottom to open it.

  2. Run the atomic service in DevEco Studio. For details, see Running an Atomic Service on a Local Real Device.

  3. Debugging covers two layers: the view layer (Webview) and the logic layer (V8 engine). For details, see Debugging and Running ASCF Source Code.

    Click in the ASCF Debugger, and logic layer (V8 engine) debugging will be initiated automatically in DevEco Studio, as shown in the figure below.

    Open chrome://inspect/#devices in a browser to debug the view layer (Webview).

  4. Click in the ASCF Debugger to stop debugging.

[h2]Opening the Debugging Page Using Commands

In debug mode, run the following commands in the root directory of the ASCF project to enable or disable debugging.

Enabling Webview debugging and V8 engine debugging:

ascf debugger start

After the command is executed successfully, open the debugger page in Chrome based on the log prompts.

Opening the V8 engine debugging page in the browser:

ascf debugger start -o

Disabling Webview debugging and V8 engine debugging:

ascf debugger stop

Enabling Webview debugging:

ascf debugger start-view

Disabling Webview debugging:

ascf debugger stop-view

Enabling V8 engine debugging:

ascf debugger start-service

Disabling V8 engine debugging:

ascf debugger stop-service

Checking the current debugging status:

ascf debugger status

[h2]Opening the Debugging Page via Chrome

  1. When the device running HarmonyOS 5.0 or later is connected and the ascf debugger start -ct hdc command is executed, enter chrome://inspect/#devices in the address box of Chrome on the PC and open the page.

    When the device running HarmonyOS 4 or earlier is connected and the ascf debugger start -ct adb command is executed, obtain the debug address by searching the logs for the keyword start debug server url, enter the debug address in the address box of Chrome on the PC, and open the page.

  2. Configure the Chrome debugging tool.

    The web page to be debugged needs to be discovered from the local TCP ports 9222 and 9229. Therefore, ensure that Discover network targets is selected. Then, configure the network. Port 9222 corresponds to the Webview debugging window, and port 9229 corresponds to the V8 engine debugging window.

    (1) Click the Configure button.

    (2) Add localhost:9222 and localhost:9229 to Target discovery settings.

[h2]Network Debugging

Open Chrome DevTools and click Network. The panel displays the resources requested by has.download, has.upload, has.request, and has.getImageInfo. Click a request on the panel to view detailed network request information.

Currently, network debugging is supported only on devices running HarmonyOS 4 or earlier.

[h2]Parameters Supported by the Debugging Function of ASCF Toolkit

You can run the following command to obtain the help information about the parameters of the CLI tool debugging function:

ascf debugger start --help

Debugging

Option Function
--bundleName

Name of the ASCF package to debug.

Example:

ascf debugger start --bundleName com.atomicservice.1234568789

--open [chrome|edge] Browser to open the V8 engine debugging page. Chrome and Edge are supported.
--deviceId

ID of the device for debugging when the PC is connected to multiple devices.

Example:

ascf debugger start --deviceId 123456789

You can run the hdc list targets command to query all connected target devices.

-ct

--connectorType

Type of the device debugging tool. Both hdc and adb are supported. The default value is hdc. When debugging on a device running HarmonyOS 4 or earlier, you need to set the type to adb.

If the preceding commands are not supported, upgrade ASCF Toolkit to 1.0.5 or later, or perform the following operations:

[h2]Handling Debugging Activation Failures

If you encounter debugging activation failures (error: getDebugger[fport]error; [fport]: defaulting to 9222/9229) and cannot address them even after troubleshooting as prompted by the logs, this may be due to the ASCF Toolkit version being 1.0.9 or earlier, where the PC resolves localhost to an IPv6 address, causing ASCF Toolkit to fail to detect the port correctly. Upgrade the ASCF Toolkit to version 1.0.10 or later and try again.

ASCF Console

To view logs from the ASCF Console and information about calls to the has APIs, you can configure {"enableDevtools": true} in the ascf.config.json file to enable the debug panel.

If is displayed on the page, the debug panel is successfully enabled.

Enabling the debug console may affect the page loading duration. Therefore, you are advised not to enable it in production environments.

The debug console mainly provides the following functions:

[h2]Console Logs

[h2]Api (API Calls and Network Requests)

[h2]Storage (Local Storage)

Viewing ASCF Logs

In DevEco Studio, open the bottom log panel, select the atomic service you are developing, and search for the keywords 006F or ascf-app to check for any warnings or errors.

To develop with ASCF Assistant in VS Code and view the developer-printed logs, see Enabling HiLog.

If an error message contains "xxx is not defined," the corresponding API might not yet be implemented in the atomic service, and the API needs to be adapted.

Debugging with ASCF Assistant

  1. Click the debug button at the bottom of VS Code to compile and run the atomic service and launch the debugging page.

  2. Debugging covers two layers: the view layer (Webview) and the logic layer (V8 engine). For details, see Debugging and Running ASCF Source Code.

    The logic layer (V8 engine) debugging will be initiated automatically in VS Code, as shown in the figure below.

    Open chrome://inspect/#devices in a browser to debug the view layer (Webview).