DEV Community

SameX
SameX

Posted on

Unraveling the Mysteries of ArkWeb: Understanding the Architecture and Lifecycle Management

This article aims to deeply explore the technical details of the Huawei HarmonyOS Next system (up to API 12 as of now), and is summarized based on actual development practices.
It mainly serves as a vehicle for technical sharing and communication. Mistakes and omissions are inevitable. Colleagues are welcome to put forward valuable opinions and questions so that we can make progress together.
This article is original content, and any form of reprint must indicate the source and the original author.

ArkWeb (Ark Web) is an important component of the Huawei HarmonyOS Next system, providing developers with a way to embed and display Web page content within an application. In this article, we will start with an introduction to ArkWeb and gradually delve into the details of its lifecycle management, helping readers better understand and utilize this powerful technology.

I. Introduction to ArkWeb

1. What is ArkWeb

ArkWeb (Ark Web) is a Web component framework based on the Ark Compiler launched by Huawei, aiming to provide developers with a more convenient and efficient Web development experience. It supports embedding Web page content within an application and is suitable for various application scenarios, such as integrating Web pages into applications, browser web browsing scenarios, and mini-program rendering.

2. The Development History of ArkWeb

The development of ArkWeb began with Huawei's in-depth research and exploration of Web technology. With the advancement of Huawei's all-scenario intelligent strategy, ArkWeb has gradually become an important part of the Huawei HarmonyOS ecosystem.

3. The Advantages and Characteristics of ArkWeb

  • High Performance: Based on the Google Chromium kernel, it provides fast page loading and a smooth interaction experience.
  • Rich Functions: Supports JavaScript interaction, cookie management, caching and storage, etc., meeting various development needs.
  • Good Compatibility: Compatible with Web page standards, ensuring consistent page performance on different devices.
  • Easy Integration: Seamlessly integrates with other Huawei technologies and services, such as HarmonyOS and Huawei Cloud.
  • Integrating Web Pages into Applications: Developers can embed Web components into applications to display Web content, reducing development costs and improving development efficiency.
  • Browser Web Browsing Scenarios: Browser applications can use ArkWeb components to open third-party web pages and provide features such as incognito browsing mode and ad blocking.
  • Mini-program Rendering: As the host application of mini-programs, it can use ArkWeb components to render the pages of mini-programs.

The advantages of ArkWeb lie in its high performance, rich functions, good compatibility, and easy integration. It is developed based on the Google Chromium kernel, ensuring the consistent display of Web pages on different devices and seamless integration with other Huawei technologies and services.

II. ArkWeb Lifecycle Management

Lifecycle management is one of the core features of ArkWeb, allowing developers to control the loading status of Web pages and interact with them. The lifecycle of an ArkWeb component mainly includes the following stages:

  1. Creation: Create an instance of the Web component. At this time, the component has not loaded any Web pages.
  2. Loading: Developers can declaratively load Web pages or use off-screen loading methods.
  3. Interaction: After the Web page is loaded, developers can interact with the Web page through JavaScriptProxy.
  4. Lifecycle State Changes: The ArkWeb component notifies the Web page of lifecycle state changes, such as page start loading, loading completion, and page destruction.
  5. Destruction: When the Web component is no longer needed, it can be destroyed to release resources.

Through lifecycle management, developers can better control the behavior of Web pages. For example, they can display a loading indicator during page loading or provide a retry mechanism when page loading fails.

The following is a simple code example of ArkWeb lifecycle management, showing how to handle Web pages in different lifecycle stages:

// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
    controller: webview.WebviewController = new webview.WebviewController();
    build() {
        Column() {
            Web({
                src: 'https://www.example.com',
                controller: this.controller
            })
          .onLoadStart(() => {
                console.log('Web page loading start');
            })
          .onLoadEnd(() => {
                console.log('Web page loading end');
            })
          .onShow(() => {
                console.log('Web page shown');
            })
          .onHide(() => {
                console.log('Web page hidden');
            });
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

In this example, we define a Web component and add corresponding processing logic in different stages of its lifecycle. For example, in the onLoadStart and onLoadEnd events, we can handle the start and end of page loading; in the onShow and onHide events, we can handle the display and hiding of the page.

In this way, developers can better control the behavior of Web pages, such as displaying a loading indicator during page loading or providing a retry mechanism when page loading fails.

III. Summary

As an important part of the Huawei HarmonyOS Next system, ArkWeb provides developers with an efficient and flexible way to integrate Web content. By deeply understanding the introduction and lifecycle management of ArkWeb, developers can better utilize this tool to create more rich and interactive applications. With the continuous development and improvement of ArkWeb technology, it will play an increasingly important role in all-scenario intelligent application development.

Top comments (0)