Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Implementing Core Browser Features in HarmonyOS using Web Components

Notes Nov 12 19

This demonstration illustrates how to construct a basic browser application within HarmonyOS. It utilizes the @ohos.systemparameter interface alongside the native Web component to enable core functionalities such as rendering web content and managing the navigation history stack.

Application Usage

  • Ensure an active Wi-Fi connection is established before launching the application to view the default homepage.
  • Navigate to specific websites by either clicking icons on the default page or entering a URL manually into the input field and triggering the navigation action.
  • Traverse the browsing history using the directional controls located near the address bar to move forward or backward through previously visited pages.
  • Return to the startup screen via the home icon, or initiate a new browsing session by tapping the add button.

Project Structure

The source code is organized to separate concerns between the UI, logic, and utility layers:

entry/src/main/ets/
├── Application/
│   └── AbilityStage.ets        // Application entry point
├── pages/
│   └── Index.ets                // Main UI layout
├── common/
│   ├── PhoneLayout.ets         // Window management utilities
│   └── TitleBar.ets            // Navigation bar component
└── model/
    ├── Logger.ts               // Logging mechanism
    └── Browser.ets             // Core browser logic and instance

Technical Implementation

The browser's navigation and rendering logic are primarily encapsulated within the Browser module.

Page Loading and Refreshing: The WebController API is central to the operation. To display web content, the loadUrl() method is invoked with the target address. For updating the current view, the controller's refresh() method is utilized.

History Stack Navigation: Implementing forward and backward navigation requires checking the history state before execution. The controller provides accessForward() and accessBackward() methods to verify if corresponding history entries exist. Once confirmed, the actual navigation is performed using the forward() or backward() commands.

Required Permissions

To function correctly, the application requires the following permissions in the configuration file:

  • ohos.permission.INTERNET
  • ohos.permission.GET_WIFI_INFO

Constraints and Requirements

  • This implementation is designed for standard system devices only.
  • Interaction requires an external pointing device (mouse) for verification.
  • The project is compatible with API version 9 (SDK version 3.2.11.9).
  • Tab switching functionality is not supported in this version.
  • Accessing the @ohos.systemparameter system interface requires the Full SDK; compilation will fail with the public SDK.
  • Development requires DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400) or later.

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Skipping Errors in MySQL Asynchronous Replication

When a replica halts because the SQL thread encounters an error, you can resume replication by skipping the problematic event(s). Two common approaches are available. Methods to Skip Errors 1) Skip a...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.