鸿蒙cordova的Ionic-webview插件
| Files | Last commit | Last update |
|---|---|---|
| 8 months ago | ||
| 9 months ago | ||
| 11 months ago | ||
| 9 months ago | ||
| 4 months ago | ||
| 4 months ago | ||
| 4 months ago | ||
| 4 months ago |
cordova-plugin-ionic-webview
This project is developed based on cordova-plugin-ionic-webview@5.0.1. This document focuses on its specific application in the OpenHarmony (OHOS) system.
- cordova-plugin-ionic-webview
Introduction
cordova-plugin-ionic-webview is a core plugin in the Harmony Cordova ecosystem, providing a high-performance, modern WebView solution for Apache Cordova / Ionic applications, replacing the native Cordova WebView, optimizing loading speed, local resource access, and cross-origin compatibility. This document mainly describes its application in the OHOS system.
Core Features
-
Performance Optimization: Based on Chrome kernel, loading speed increased by 30%+, supports hardware acceleration
-
Local Resource Access: Efficiently accesses local files (HTML/CSS/JS/images, etc.) via
http(s)://protocol, supports offline caching -
Cross-Origin Friendly: Built-in CORS support enables cross-origin requests without additional configuration
-
Modern Features: Supports ES6+ syntax, WebGL, Service Worker, WebRTC, and other modern web features
-
Security Enhancement: Supports HTTPS enforcement mode, Content Security Policy (CSP), prevents mixed content warnings
-
Ionic Compatibility: Deeply integrated with Ionic Framework, perfectly supports Ionic application routing, animations, and components
-
Convenient Debugging: Supports remote debugging with web debugging tools
Supported Platforms
-
Android: API 19+ (Android 4.4+)
-
iOS: 10.0+
-
OHOS: 5.0+
Installation
Plugins can be quickly installed via the hcordova CLI, available from the npm registry or the GitCode repository. Stable versions, specific versions, or development versions can be selected as needed.
Basic Installation (Recommended)
# Install hcordova CLI tool
npm install -g hcordova
# Install the latest stable version plugin
hcordova plugin add cordova-plugin-ionic-webview
Install for OHOS Platform
Install the plugin only for the OHOS platform, with the option to specify a version:
# Install a specific version (e.g., 1.0.0) and specify OHOS platform
hcordova plugin add cordova-plugin-ionic-webview@1.0.0 --platform ohos
Install from GitCode Repository
Install the plugin only for the OHOS platform (development version, get the latest code from the main branch):
# Install the latest development version from the main branch and specify OHOS platform
hcordova plugin add https://gitcode.com/CPF-Cordova/cordova-plugin-ionic-webview.git --platform ohos
# Install from specific tag/branch
hcordova plugin add https://gitcode.com/CPF-Cordova/cordova-plugin-ionic-webview.git@develop --platform ohos
Offline Installation (Local Package)
For environments without network access, download the plugin package locally first, then perform offline installation:
# Download the plugin package locally (example path: ~/Downloads/cordova-plugin-ionic-webview)
# Perform offline installation
hcordova plugin add ~/Downloads/cordova-plugin-ionic-webview --platform ohos
Post-Installation Verification
After installation, verify that the plugin has been successfully added to the project using the following command:
# List installed plugins; if the plugin ID appears, the plugin was successfully installed
hcordova plugin list
Uninstallation
# Uninstall from all platforms using Cordova CLI
hcordova plugin rm cordova-plugin-ionic-webview
# Uninstall from OHOS platform only
hcordova plugin rm cordova-plugin-ionic-webview --platform ohos
Constraints and Limitations
- The plugin replaces the native Cordova WebView; after installation, it will overwrite native WebView-related configurations. It is recommended to back up project configurations before installation.
- On the OHOS platform, the default file loaded is Rawfile/www/index.html via https://www.example.com. Custom schemes and domain names can be configured via config.cml.
- Page loading in the OHOS system is implemented by the existing @cordova-ohos/ohos framework.
- Ensure project compatibility with Chrome kernel-related features; some older web syntax may require adaptation adjustments.
- After enabling HTTPS enforcement mode, ensure all resource access uses the HTTPS protocol to avoid mixed content warnings.
Compatibility
Supported:
| Item | Version/Info |
|---|---|
| SDK | API12+ |
| IDE | DevEco Studio: 5.0+ |
| ROM | 5.1+ |
| Emulator | OpenHarmony 6.0+ |
Tested with the following versions:
| Item | Version/Info |
|---|---|
| @cordova-ohos/ohos | 14.0.1-ohos-14.0.1 |
| SDK | 5.0.0(12) |
| IDE | DevEco Studio: 6.0.13.200 |
| ROM | 5.1.0.120 SP3 |
| Emulator | OpenHarmony 6.0.1(21) |
Usage Instructions
Configuration Instructions
1. Basic Configuration (Optional)
The default file loaded is Rawfile/www/index.html via https://www.example.com. Custom schemes and domain names can be configured via config.cml.
config.cml Configuration
<!-- Configure the loading scheme, supports http|https, https is recommended by default -->
<preference name="Scheme" value="https" />
<!-- Configure custom loading domain name -->
<preference name="Hostname" value="app" />
Important Notes
- When configuring the scheme, only http and https are supported. https is recommended to enhance security.
- Custom hostnames must comply with domain name specifications, avoiding special characters.
- During debugging, remote debugging via web debugging tools is available to improve development efficiency.
- If offline caching functionality is needed, ensure local resource paths are correctly configured to support access via the http(s)😕/ protocol.
New Features
- Adapted for OHOS 5.0+ system, strictly following OpenHarmony development specifications, replacing the native Cordova WebView.
- Retains core plugin functionality, optimizes local resource access efficiency on the OHOS platform, supports http(s)😕/ protocol for accessing local files.
- Improved configuration instructions for the OHOS platform, clarifying config.cml configuration methods and parameter meanings.
- Compatible with Cordova 14.0.1-ohos version, deeply integrated with Ionic Framework to ensure smooth application operation.
Directory Structure
cordova-plugin-ionic-webview/
├── src/ # Source code directory
│ └── main/ # Main source code
│ └── cpp/ # C++ native code
│ ├── IonicWebView/ # Ionic WebView module
│ │ ├── IonicWebView.cpp # C++ implementation of Ionic WebView functionality
│ │ └── IonicWebView.h # Header file for Ionic WebView functionality
│ └── NativeStorage/ # Native storage module
│ ├── NativeStorage.cpp # C++ implementation of native storage functionality
│ └── NativeStorage.h # Header file for native storage functionality
├── www/ # Web resource directory
│ └── util.js # JavaScript utility function interface (Cordova bridge layer)
├── .gitignore # Git ignore file configuration
├── LICENSE # Project open source license
├── OAT.xml # OpenHarmony review configuration file
├── package.json # Node.js package configuration
├── plugin.xml # Cordova plugin description file (core configuration)
└── README.md # Project documentation
Contribute
If you encounter any issues during use, please feel free to submit an Issue. Pull requests PR for collaborative development are also very welcome.
License
This plugin is open-sourced under the Apache License 2.0, freely available for commercial and non-commercial projects. See the LICENSE file for details.
Official Resources
-
Android and iOS: cordova-plugin-ionic-webview Official Guide
-
GitCode Repository: CPF-Cordova/cordova-plugin-ionic-webview