提交 e9459a39 编写于 作者: E ester.zhou

Update docs (14819)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 1a5185cf
...@@ -27,7 +27,7 @@ In the [NotificationTemplate](../reference/apis/js-apis-notificationManager.md#n ...@@ -27,7 +27,7 @@ In the [NotificationTemplate](../reference/apis/js-apis-notificationManager.md#n
```ts ```ts
notificationManager.isSupportTemplate('downloadTemplate').then((data) => { notificationManager.isSupportTemplate('downloadTemplate').then((data) => {
console.info(`[ANS] isSupportTemplate success`); console.info(`[ANS] isSupportTemplate success`);
let isSupportTpl: boolean = data; // The value **true** means that the template of the **downloadTemplate** type is supported; and false means the opposite. let isSupportTpl: boolean = data; // The value true means that the template of the downloadTemplate type is supported, and false means the opposite.
// ... // ...
}).catch((err) => { }).catch((err) => {
console.error(`[ANS] isSupportTemplate failed, code is ${err.code}, message is ${err.message}`); console.error(`[ANS] isSupportTemplate failed, code is ${err.code}, message is ${err.message}`);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# @ohos.web.webview (Webview) # @ohos.web.webview (Webview)
The **Webview** module provides APIs for web control. The **Webview** module provides APIs for web control. It can be used with the **[<Web\>](../arkui-ts/ts-basic-components-web.md)** component, which can be used to display web pages.
> **NOTE** > **NOTE**
> >
...@@ -20,7 +20,7 @@ The **Webview** module provides APIs for web control. ...@@ -20,7 +20,7 @@ The **Webview** module provides APIs for web control.
import web_webview from '@ohos.web.webview'; import web_webview from '@ohos.web.webview';
``` ```
### once ## once
once(type: string, callback: Callback\<void\>): void once(type: string, callback: Callback\<void\>): void
...@@ -43,7 +43,7 @@ import web_webview from '@ohos.web.webview' ...@@ -43,7 +43,7 @@ import web_webview from '@ohos.web.webview'
web_webview.once("webInited", () => { web_webview.once("webInited", () => {
console.log("setCookie") console.log("setCookie")
web_webview.WebCookieManager.setCookie("www.example.com", "a=b") web_webview.WebCookieManager.setCookie("https://www.example.com", "a=b")
}) })
@Entry @Entry
...@@ -245,6 +245,44 @@ export default class EntryAbility extends UIAbility { ...@@ -245,6 +245,44 @@ export default class EntryAbility extends UIAbility {
} }
``` ```
### setHttpDns<sup>10+</sup>
static setHttpDns(secureDnsMode:SecureDnsMode, secureDnsConfig:string): void
Sets how the \<Web> component uses HTTPDNS for DNS resolution.
**System capability**: SystemCapability.Web.Webview.Core
**Parameters**
| Name | Type | Mandatory | Description|
| ------------------ | ------- | ---- | ------------- |
| secureDnsMode | [SecureDnsMode](#securednsmode) | Yes | Mode in which HTTPDNS is used.|
| secureDnsConfig | string | Yes| Information about the HTTPDNS server to use, which must use HTTPS. Only one HTTPDNS server can be configured.|
**Example**
```ts
// xxx.ts
import UIAbility from '@ohos.app.ability.UIAbility';
import web_webview from '@ohos.web.webview';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log("EntryAbility onCreate")
web_webview.WebviewController.initializeWebEngine()
try {
web_webview.WebviewController.setHttpDns(web_webview.SecureDnsMode.Auto, "https://example1.test")
} catch(error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
globalThis.abilityWant = want
console.log("EntryAbility onCreate done")
}
}
```
### Creating an Object ### Creating an Object
```ts ```ts
...@@ -379,12 +417,12 @@ struct WebComponent { ...@@ -379,12 +417,12 @@ struct WebComponent {
} }
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.webDebuggingAccess(true)
} }
} }
} }
``` ```
Example of loading local web pages:
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
...@@ -399,7 +437,7 @@ struct WebComponent { ...@@ -399,7 +437,7 @@ struct WebComponent {
Button('loadUrl') Button('loadUrl')
.onClick(() => { .onClick(() => {
try { try {
// The URL to be loaded is of the Resource type. // Load a local resource file through $rawfile.
this.controller.loadUrl($rawfile('xxx.html')); this.controller.loadUrl($rawfile('xxx.html'));
} catch (error) { } catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
...@@ -411,6 +449,32 @@ struct WebComponent { ...@@ -411,6 +449,32 @@ struct WebComponent {
} }
``` ```
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('loadUrl')
.onClick(() => {
try {
// Load a local resource file through the resource protocol.
this.controller.loadUrl("resource://rawfile/xxx.html");
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
```html ```html
<!-- xxx.html --> <!-- xxx.html -->
<!DOCTYPE html> <!DOCTYPE html>
...@@ -479,7 +543,34 @@ struct WebComponent { ...@@ -479,7 +543,34 @@ struct WebComponent {
} }
``` ```
### accessforward Example of loading local resource:
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
updataContent: string = '<body><div><image src=resource://rawfile/xxx.png alt="image -- end" width="500" height="250"></image></div></body>'
build() {
Column() {
Button('loadData')
.onClick(() => {
try {
this.controller.loadData(this.updataContent, "text/html", "UTF-8", " ", " ");
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### accessForward
accessForward(): boolean accessForward(): boolean
...@@ -1606,7 +1697,7 @@ struct WebComponent { ...@@ -1606,7 +1697,7 @@ struct WebComponent {
.onClick(() => { .onClick(() => {
try { try {
if (this.ports && this.ports[1]) { if (this.ports && this.ports[1]) {
this.ports[1].postMessageEvent("this.sendFromEts"); this.ports[1].postMessageEvent(this.sendFromEts);
} else { } else {
console.error(`ports is null, Please initialize first`); console.error(`ports is null, Please initialize first`);
} }
...@@ -1648,7 +1739,7 @@ var output = document.querySelector('.output'); ...@@ -1648,7 +1739,7 @@ var output = document.querySelector('.output');
window.addEventListener('message', function (event) { window.addEventListener('message', function (event) {
if (event.data == '__init_port__') { if (event.data == '__init_port__') {
if (event.ports[0] != null) { if (event.ports[0] != null) {
The h5Port = event.ports[0]; // 1. Save the port number sent from the eTS side. h5Port = event.ports[0]; // 1. Save the port number sent from the eTS side.
h5Port.onmessage = function (event) { h5Port.onmessage = function (event) {
// 2. Receive the message sent from the eTS side. // 2. Receive the message sent from the eTS side.
var msg = 'Got message from ets:'; var msg = 'Got message from ets:';
...@@ -3167,6 +3258,358 @@ struct WebComponent { ...@@ -3167,6 +3258,358 @@ struct WebComponent {
} }
``` ```
### getCertificate<sup>10+</sup>
getCertificate(): Promise<Array<cert.X509Cert>>
Obtains the certificate information of the current website. When the \<Web> component is used to load an HTTPS website, SSL certificate verification is performed. This API uses a promise to return the [X.509 certificate](./js-apis-cert.md) of the current website.
**System capability**: SystemCapability.Web.Webview.Core
**Return value**
| Type | Description |
| ---------- | --------------------------------------------- |
| Promise<Array<cert.X509Cert>> | Promise used to obtain the X.509 certificate array of the current HTTPS website.|
**Error codes**
For details about the error codes, see [Webview Error Codes](../errorcodes/errorcode-webview.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
function Uint8ArrayToString(dataArray) {
var dataString = ''
for (var i = 0; i < dataArray.length; i++) {
dataString += String.fromCharCode(dataArray[i])
}
return dataString
}
function ParseX509CertInfo(x509CertArray) {
let res: string = 'getCertificate success: len = ' + x509CertArray.length;
for (let i = 0; i < x509CertArray.length; i++) {
res += ', index = ' + i + ', issuer name = '
+ Uint8ArrayToString(x509CertArray[i].getIssuerName().data) + ', subject name = '
+ Uint8ArrayToString(x509CertArray[i].getSubjectName().data) + ', valid start = '
+ x509CertArray[i].getNotBeforeTime()
+ ', valid end = ' + x509CertArray[i].getNotAfterTime()
}
return res
}
@Entry
@Component
struct Index {
// outputStr displays debug information on the UI.
@State outputStr: string = ''
webviewCtl: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Row() {
Column() {
List({space: 20, initialIndex: 0}) {
ListItem() {
Button() {
Text('load bad ssl')
.fontSize(10)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.onClick(() => {
// Load an expired certificate website and view the obtained certificate information.
this.webviewCtl.loadUrl('https://expired.badssl.com')
})
.height(50)
}
ListItem() {
Button() {
Text('load example')
.fontSize(10)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.onClick(() => {
//Load an HTTPS website and view the certificate information of the website.
this.webviewCtl.loadUrl('https://www.example.com')
})
.height(50)
}
ListItem() {
Button() {
Text('getCertificate Promise')
.fontSize(10)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.onClick(() => {
try {
this.webviewCtl.getCertificate().then(x509CertArray => {
this.outputStr = ParseX509CertInfo(x509CertArray);
})
} catch (error) {
this.outputStr = 'getCertificate failed: ' + error.code + ", errMsg: " + error.message;
}
})
.height(50)
}
ListItem() {
Button() {
Text('getCertificate AsyncCallback')
.fontSize(10)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.onClick(() => {
try {
this.webviewCtl.getCertificate((error, x509CertArray) => {
if (error) {
this.outputStr = 'getCertificate failed: ' + error.code + ", errMsg: " + error.message;
} else {
this.outputStr = ParseX509CertInfo(x509CertArray);
}
})
} catch (error) {
this.outputStr = 'getCertificate failed: ' + error.code + ", errMsg: " + error.message;
}
})
.height(50)
}
}
.listDirection(Axis.Horizontal)
.height('10%')
Text(this.outputStr)
.width('100%')
.fontSize(10)
Web({ src: 'https://www.example.com', controller: this.webviewCtl })
.fileAccess(true)
.javaScriptAccess(true)
.domStorageAccess(true)
.onlineImageAccess(true)
.onPageEnd((e) => {
this.outputStr = 'onPageEnd : url = ' + e.url
})
.onSslErrorEventReceive((e) => {
// Ignore SSL certificate errors to test websites whose certificates have expired, for example, https://expired.badssl.com.
e.handler.handleConfirm()
})
.width('100%')
.height('70%')
}
.height('100%')
}
}
}
```
### getCertificate<sup>10+</sup>
getCertificate(callback: AsyncCallback<Array<cert.X509Cert>>): void
Obtains the certificate information of the current website. When the \<Web> component is used to load an HTTPS website, SSL certificate verification is performed. This API uses an asynchronous callback to return the [X.509 certificate](./js-apis-cert.md) of the current website.
**System capability**: SystemCapability.Web.Webview.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<Array<cert.X509Cert>> | Yes | Callback used to obtain the X.509 certificate array of the current HTTPS website.|
**Error codes**
For details about the error codes, see [Webview Error Codes](../errorcodes/errorcode-webview.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web compoent. |
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
function Uint8ArrayToString(dataArray) {
var dataString = ''
for (var i = 0; i < dataArray.length; i++) {
dataString += String.fromCharCode(dataArray[i])
}
return dataString
}
function ParseX509CertInfo(x509CertArray) {
let res: string = 'getCertificate success: len = ' + x509CertArray.length;
for (let i = 0; i < x509CertArray.length; i++) {
res += ', index = ' + i + ', issuer name = '
+ Uint8ArrayToString(x509CertArray[i].getIssuerName().data) + ', subject name = '
+ Uint8ArrayToString(x509CertArray[i].getSubjectName().data) + ', valid start = '
+ x509CertArray[i].getNotBeforeTime()
+ ', valid end = ' + x509CertArray[i].getNotAfterTime()
}
return res
}
@Entry
@Component
struct Index {
// outputStr displays debug information on the UI.
@State outputStr: string = ''
webviewCtl: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Row() {
Column() {
List({space: 20, initialIndex: 0}) {
ListItem() {
Button() {
Text('load bad ssl')
.fontSize(10)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.onClick(() => {
// Load an expired certificate website and view the obtained certificate information.
this.webviewCtl.loadUrl('https://expired.badssl.com')
})
.height(50)
}
ListItem() {
Button() {
Text('load example')
.fontSize(10)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.onClick(() => {
//Load an HTTPS website and view the certificate information of the website.
this.webviewCtl.loadUrl('https://www.example.com')
})
.height(50)
}
ListItem() {
Button() {
Text('getCertificate Promise')
.fontSize(10)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.onClick(() => {
try {
this.webviewCtl.getCertificate().then(x509CertArray => {
this.outputStr = ParseX509CertInfo(x509CertArray);
})
} catch (error) {
this.outputStr = 'getCertificate failed: ' + error.code + ", errMsg: " + error.message;
}
})
.height(50)
}
ListItem() {
Button() {
Text('getCertificate AsyncCallback')
.fontSize(10)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.onClick(() => {
try {
this.webviewCtl.getCertificate((error, x509CertArray) => {
if (error) {
this.outputStr = 'getCertificate failed: ' + error.code + ", errMsg: " + error.message;
} else {
this.outputStr = ParseX509CertInfo(x509CertArray);
}
})
} catch (error) {
this.outputStr = 'getCertificate failed: ' + error.code + ", errMsg: " + error.message;
}
})
.height(50)
}
}
.listDirection(Axis.Horizontal)
.height('10%')
Text(this.outputStr)
.width('100%')
.fontSize(10)
Web({ src: 'https://www.example.com', controller: this.webviewCtl })
.fileAccess(true)
.javaScriptAccess(true)
.domStorageAccess(true)
.onlineImageAccess(true)
.onPageEnd((e) => {
this.outputStr = 'onPageEnd : url = ' + e.url
})
.onSslErrorEventReceive((e) => {
// Ignore SSL certificate errors to test websites whose certificates have expired, for example, https://expired.badssl.com.
e.handler.handleConfirm()
})
.width('100%')
.height('70%')
}
.height('100%')
}
}
}
```
### setAudioMuted
setAudioMuted(mute: boolean): void
Mutes this web page.
**System capability**: SystemCapability.Web.Webview.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------- | ---- | -------------------------------------- |
| mute | boolean | Yes | Whether to mute the web page. The value **true** means to mute the web page, and **false** means the opposite.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController()
@State muted: boolean = false
build() {
Column() {
Button("Toggle Mute")
.onClick(event => {
this.muted = !this.muted
this.controller.setAudioMuted(this.muted)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
## WebCookieManager ## WebCookieManager
Implements a **WebCookieManager** instance to manage behavior of cookies in **\<Web>** components. All **\<Web>** components in an application share a **WebCookieManager** instance. Implements a **WebCookieManager** instance to manage behavior of cookies in **\<Web>** components. All **\<Web>** components in an application share a **WebCookieManager** instance.
...@@ -3215,7 +3658,7 @@ struct WebComponent { ...@@ -3215,7 +3658,7 @@ struct WebComponent {
Button('getCookie') Button('getCookie')
.onClick(() => { .onClick(() => {
try { try {
let value = web_webview.WebCookieManager.getCookie('www.example.com'); let value = web_webview.WebCookieManager.getCookie('https://www.example.com');
console.log("value: " + value); console.log("value: " + value);
} catch (error) { } catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
...@@ -3267,7 +3710,7 @@ struct WebComponent { ...@@ -3267,7 +3710,7 @@ struct WebComponent {
Button('setCookie') Button('setCookie')
.onClick(() => { .onClick(() => {
try { try {
web_webview.WebCookieManager.setCookie('www.example.com', 'a=b'); web_webview.WebCookieManager.setCookie('https://www.example.com', 'a=b');
} catch (error) { } catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
} }
...@@ -4135,9 +4578,6 @@ struct WebComponent { ...@@ -4135,9 +4578,6 @@ struct WebComponent {
try { try {
this.username_password = web_webview.WebDataBase.getHttpAuthCredentials(this.host, this.realm); this.username_password = web_webview.WebDataBase.getHttpAuthCredentials(this.host, this.realm);
console.log('num: ' + this.username_password.length); console.log('num: ' + this.username_password.length);
ForEach(this.username_password, (item) => {
console.log('username_password: ' + item);
}, item => item)
} catch (error) { } catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
} }
...@@ -4206,7 +4646,7 @@ Checks whether any saved HTTP authentication credentials exist. This API returns ...@@ -4206,7 +4646,7 @@ Checks whether any saved HTTP authentication credentials exist. This API returns
| Type | Description | | Type | Description |
| ------- | ------------------------------------------------------------ | | ------- | ------------------------------------------------------------ |
| boolean | Whether any saved HTTP authentication credentials exist. Returns **true** if any saved HTTP authentication credentials exist; returns **false** otherwise. | | boolean | Whether any saved HTTP authentication credentials exist. Returns **true** if any saved HTTP authentication credentials exist; returns **false** otherwise.|
**Example** **Example**
...@@ -4771,3 +5211,15 @@ Defines a custom URL scheme. ...@@ -4771,3 +5211,15 @@ Defines a custom URL scheme.
| schemeName | string | Yes | Yes | Name of the custom URL scheme. The value can contain a maximum of 32 characters and include only lowercase letters, digits, periods (.), plus signs (+), and hyphens (-). | | schemeName | string | Yes | Yes | Name of the custom URL scheme. The value can contain a maximum of 32 characters and include only lowercase letters, digits, periods (.), plus signs (+), and hyphens (-). |
| isSupportCORS | boolean | Yes | Yes | Whether to support cross-origin resource sharing (CORS). | | isSupportCORS | boolean | Yes | Yes | Whether to support cross-origin resource sharing (CORS). |
| isSupportFetch | boolean | Yes | Yes | Whether to support fetch requests. | | isSupportFetch | boolean | Yes | Yes | Whether to support fetch requests. |
## SecureDnsMode<sup>10+</sup>
Describes the mode in which the **\<Web>** component uses HTTPDNS.
**System capability**: SystemCapability.Web.Webview.Core
| Name | Value| Description |
| ------------- | -- |----------------------------------------- |
| Off | 0 |HTTPDNS is not used. This value can be used to revoke the previously used HTTPDNS configuration.|
| Auto | 1 |HTTPDNS is used in automatic mode. When the specified HTTPDNS server is unavailable for resolution, the component will fall back to the system DNS server.|
| SecureOnly | 2 |The specified HTTPDNS server is forcibly used for DNS resolution.|
# Web # Web
The **<Web\>** component can be used to display web pages. The **<Web\>** component can be used to display web pages. It can be used with the [@ohos.web.webview](../apis/js-apis-webview.md) module, which provides APIs for web control.
> **NOTE** > **NOTE**
> >
...@@ -16,29 +16,32 @@ Not supported ...@@ -16,29 +16,32 @@ Not supported
## APIs ## APIs
Web(options: { src: ResourceStr, controller: WebController | WebviewController}) Web(options: { src: ResourceStr, controller: WebviewController | WebController})
> **NOTE** > **NOTE**
> >
> Transition animation is not supported. > Transition animation is not supported.
> Different **\<Web>** components on the same page must be bound to different **WebController**s. >
> **\<Web>** components on a page must be bound to different **WebviewController**s.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------- | ---------------------------------------- | ---- | ------- | | ---------- | ---------------------------------------- | ---- | ------- |
| src | [ResourceStr](ts-types.md) | Yes | Address of a web page resource.| | src | [ResourceStr](ts-types.md) | Yes | Address of a web page resource. To access local resource files, use the **$rawfile** or **resource** protocol.|
| controller | [WebController](#webcontroller) \| [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) | Yes | Controller. | | controller | [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) \| [WebController](#webcontroller) | Yes | Controller. **WebController** is deprecated since API version 9. You are advised to use **WebviewController** instead.|
**Example** **Example**
Example of loading online web pages: Example of loading online web pages:
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -46,6 +49,8 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController}) ...@@ -46,6 +49,8 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController})
} }
} }
``` ```
Example of loading local web pages:
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
...@@ -56,22 +61,25 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController}) ...@@ -56,22 +61,25 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController})
controller: web_webview.WebviewController = new web_webview.WebviewController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) // Load a local resource file through $rawfile.
Web({ src: $rawfile("index.html"), controller: this.controller })
} }
} }
} }
``` ```
Example of loading local web pages:
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: $rawfile("index.html"), controller: this.controller }) // Load a local resource file through the resource protocol.
Web({ src: "resource://rawfile/index.html", controller: this.controller })
} }
} }
} }
...@@ -107,10 +115,12 @@ Sets whether to enable the DOM Storage API. By default, this feature is disabled ...@@ -107,10 +115,12 @@ Sets whether to enable the DOM Storage API. By default, this feature is disabled
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -136,10 +146,12 @@ Sets whether to enable access to the file system in the application. This settin ...@@ -136,10 +146,12 @@ Sets whether to enable access to the file system in the application. This settin
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -164,10 +176,12 @@ Sets whether to enable automatic image loading. By default, this feature is enab ...@@ -164,10 +176,12 @@ Sets whether to enable automatic image loading. By default, this feature is enab
**Example** **Example**
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -180,7 +194,7 @@ Sets whether to enable automatic image loading. By default, this feature is enab ...@@ -180,7 +194,7 @@ Sets whether to enable automatic image loading. By default, this feature is enab
### javaScriptProxy ### javaScriptProxy
javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Array\<string\>, javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Array\<string\>,
controller: WebController | WebviewController}) controller: WebviewController | WebController})
Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. The parameters cannot be updated. Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. The parameters cannot be updated.
...@@ -191,41 +205,10 @@ Registers a JavaScript object with the window. APIs of this object can then be i ...@@ -191,41 +205,10 @@ Registers a JavaScript object with the window. APIs of this object can then be i
| object | object | Yes | - | Object to be registered. Methods can be declared, but attributes cannot. | | object | object | Yes | - | Object to be registered. Methods can be declared, but attributes cannot. |
| name | string | Yes | - | Name of the object to be registered, which is the same as that invoked in the window.| | name | string | Yes | - | Name of the object to be registered, which is the same as that invoked in the window.|
| methodList | Array\<string\> | Yes | - | Methods of the JavaScript object to be registered at the application side. | | methodList | Array\<string\> | Yes | - | Methods of the JavaScript object to be registered at the application side. |
| controller | [WebController](#webcontroller) or [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | Yes | - | Controller. | | controller | [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) \| [WebController](#webcontroller) | Yes | - | Controller. **WebController** is deprecated since API version 9. You are advised to use **WebviewController** instead.|
**Example** **Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
testObj = {
test: (data1, data2, data3) => {
console.log("data1:" + data1)
console.log("data2:" + data2)
console.log("data3:" + data3)
return "AceString"
},
toString: () => {
console.log('toString' + "interface instead.")
}
}
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.javaScriptAccess(true)
.javaScriptProxy({
object: this.testObj,
name: "objName",
methodList: ["test", "toString"],
controller: this.controller,
})
}
}
}
```
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
...@@ -276,10 +259,12 @@ Sets whether JavaScript scripts can be executed. By default, JavaScript scripts ...@@ -276,10 +259,12 @@ Sets whether JavaScript scripts can be executed. By default, JavaScript scripts
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -305,10 +290,12 @@ Sets whether to enable loading of HTTP and HTTPS hybrid content can be loaded. B ...@@ -305,10 +290,12 @@ Sets whether to enable loading of HTTP and HTTPS hybrid content can be loaded. B
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
@State mode: MixedMode = MixedMode.All @State mode: MixedMode = MixedMode.All
build() { build() {
Column() { Column() {
...@@ -335,10 +322,12 @@ Sets whether to enable access to online images through HTTP and HTTPS. By defaul ...@@ -335,10 +322,12 @@ Sets whether to enable access to online images through HTTP and HTTPS. By defaul
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -364,10 +353,12 @@ Sets whether to enable zoom gestures. By default, this feature is enabled. ...@@ -364,10 +353,12 @@ Sets whether to enable zoom gestures. By default, this feature is enabled.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -393,10 +384,12 @@ Sets whether to load web pages by using the overview mode. By default, this feat ...@@ -393,10 +384,12 @@ Sets whether to load web pages by using the overview mode. By default, this feat
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -422,10 +415,12 @@ Sets whether to enable database access. By default, this feature is disabled. ...@@ -422,10 +415,12 @@ Sets whether to enable database access. By default, this feature is disabled.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -451,10 +446,12 @@ Sets whether to enable geolocation access. By default, this feature is enabled. ...@@ -451,10 +446,12 @@ Sets whether to enable geolocation access. By default, this feature is enabled.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -480,10 +477,12 @@ Sets whether video playback must be started by user gestures. This API is not ap ...@@ -480,10 +477,12 @@ Sets whether video playback must be started by user gestures. This API is not ap
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
@State access: boolean = true @State access: boolean = true
build() { build() {
Column() { Column() {
...@@ -510,10 +509,12 @@ Sets whether to enable the multi-window permission. ...@@ -510,10 +509,12 @@ Sets whether to enable the multi-window permission.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -539,10 +540,12 @@ Sets whether to display the horizontal scrollbar, including the default system s ...@@ -539,10 +540,12 @@ Sets whether to display the horizontal scrollbar, including the default system s
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -590,10 +593,12 @@ Sets whether to display the vertical scrollbar, including the default system scr ...@@ -590,10 +593,12 @@ Sets whether to display the vertical scrollbar, including the default system scr
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -642,10 +647,12 @@ Sets the cache mode. ...@@ -642,10 +647,12 @@ Sets the cache mode.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
@State mode: CacheMode = CacheMode.None @State mode: CacheMode = CacheMode.None
build() { build() {
Column() { Column() {
...@@ -672,10 +679,12 @@ Sets the text zoom ratio of the page. The default value is **100**, which indica ...@@ -672,10 +679,12 @@ Sets the text zoom ratio of the page. The default value is **100**, which indica
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
@State atio: number = 150 @State atio: number = 150
build() { build() {
Column() { Column() {
...@@ -702,10 +711,12 @@ Sets the scale factor of the entire page. The default value is 100%. ...@@ -702,10 +711,12 @@ Sets the scale factor of the entire page. The default value is 100%.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
@State percent: number = 100 @State percent: number = 100
build() { build() {
Column() { Column() {
...@@ -732,10 +743,12 @@ Sets the user agent. ...@@ -732,10 +743,12 @@ Sets the user agent.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
@State userAgent:string = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36' @State userAgent:string = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36'
build() { build() {
Column() { Column() {
...@@ -1196,7 +1209,9 @@ This API opens a new window when [multiWindowAccess](#multiwindowaccess9) is ena ...@@ -1196,7 +1209,9 @@ This API opens a new window when [multiWindowAccess](#multiwindowaccess9) is ena
The default value of **flag** is subject to the settings of the **persist.web.allowWindowOpenMethod.enabled** system attribute. If this attribute is not set, the default value of **flag** is **false**. The default value of **flag** is subject to the settings of the **persist.web.allowWindowOpenMethod.enabled** system attribute. If this attribute is not set, the default value of **flag** is **false**.
To check the settings of **persist.web.allowWindowOpenMethod.enabled**, run the **hdc shell param get persist.web.allowWindowOpenMethod.enabled** command. If the attribute is set to 0 or does not exist, To check the settings of **persist.web.allowWindowOpenMethod.enabled**,
run the **hdc shell param get persist.web.allowWindowOpenMethod.enabled** command. If the attribute is set to 0 or does not exist,
you can run the **hdc shell param set persist.web.allowWindowOpenMethod.enabled 1** command to enable it. you can run the **hdc shell param set persist.web.allowWindowOpenMethod.enabled 1** command to enable it.
**Parameters** **Parameters**
...@@ -1256,10 +1271,12 @@ Called when **alert()** is invoked to display an alert dialog box on the web pag ...@@ -1256,10 +1271,12 @@ Called when **alert()** is invoked to display an alert dialog box on the web pag
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -1314,10 +1331,12 @@ Called when this page is about to exit after the user refreshes or closes the pa ...@@ -1314,10 +1331,12 @@ Called when this page is about to exit after the user refreshes or closes the pa
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1375,10 +1394,12 @@ Called when **confirm()** is invoked by the web page. ...@@ -1375,10 +1394,12 @@ Called when **confirm()** is invoked by the web page.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1435,10 +1456,12 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul ...@@ -1435,10 +1456,12 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1495,10 +1518,12 @@ Called to notify the host application of a JavaScript console message. ...@@ -1495,10 +1518,12 @@ Called to notify the host application of a JavaScript console message.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1532,10 +1557,12 @@ onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisp ...@@ -1532,10 +1557,12 @@ onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisp
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1569,10 +1596,12 @@ Called when an error occurs during web page loading. For better results, simplif ...@@ -1569,10 +1596,12 @@ Called when an error occurs during web page loading. For better results, simplif
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1613,10 +1642,12 @@ Called when an HTTP error (the response code is greater than or equal to 400) oc ...@@ -1613,10 +1642,12 @@ Called when an HTTP error (the response code is greater than or equal to 400) oc
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1664,10 +1695,12 @@ Called when the web page starts to be loaded. This API is called only for the ma ...@@ -1664,10 +1695,12 @@ Called when the web page starts to be loaded. This API is called only for the ma
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1697,10 +1730,12 @@ Called when the web page loading is complete. This API takes effect only for the ...@@ -1697,10 +1730,12 @@ Called when the web page loading is complete. This API takes effect only for the
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1729,10 +1764,12 @@ Called when the web page loading progress changes. ...@@ -1729,10 +1764,12 @@ Called when the web page loading progress changes.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1761,10 +1798,12 @@ Called when the document title of the web page is changed. ...@@ -1761,10 +1798,12 @@ Called when the document title of the web page is changed.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1794,10 +1833,12 @@ Called when loading of the web page is complete. This API is used by an applicat ...@@ -1794,10 +1833,12 @@ Called when loading of the web page is complete. This API is used by an applicat
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1826,10 +1867,12 @@ Called when the rendering process exits abnormally. ...@@ -1826,10 +1867,12 @@ Called when the rendering process exits abnormally.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1865,10 +1908,12 @@ Called to process an HTML form whose input type is **file**, in response to the ...@@ -1865,10 +1908,12 @@ Called to process an HTML form whose input type is **file**, in response to the
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1914,10 +1959,12 @@ Called to notify the **\<Web>** component of the URL of the loaded resource file ...@@ -1914,10 +1959,12 @@ Called to notify the **\<Web>** component of the URL of the loaded resource file
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1947,10 +1994,12 @@ Called when the display ratio of this page changes. ...@@ -1947,10 +1994,12 @@ Called when the display ratio of this page changes.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -1985,10 +2034,12 @@ Called when the **\<Web>** component is about to access a URL. This API is used ...@@ -1985,10 +2034,12 @@ Called when the **\<Web>** component is about to access a URL. This API is used
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -2024,10 +2075,12 @@ Called when the **\<Web>** component is about to access a URL. This API is used ...@@ -2024,10 +2075,12 @@ Called when the **\<Web>** component is about to access a URL. This API is used
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
responseweb: WebResourceResponse = new WebResourceResponse() responseweb: WebResourceResponse = new WebResourceResponse()
heads:Header[] = new Array() heads:Header[] = new Array()
@State webdata: string = "<!DOCTYPE html>\n" + @State webdata: string = "<!DOCTYPE html>\n" +
...@@ -2095,7 +2148,7 @@ Called when an HTTP authentication request is received. ...@@ -2095,7 +2148,7 @@ Called when an HTTP authentication request is received.
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
httpAuth: boolean = false httpAuth: boolean = false
build() { build() {
...@@ -2157,7 +2210,7 @@ Called when an SSL error occurs during resource loading. ...@@ -2157,7 +2210,7 @@ Called when an SSL error occurs during resource loading.
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -2207,12 +2260,12 @@ Called when an SSL client certificate request is received. ...@@ -2207,12 +2260,12 @@ Called when an SSL client certificate request is received.
**Example** **Example**
```ts ```ts
// xxx.ets // xxx.ets API9
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -2244,6 +2297,106 @@ Called when an SSL client certificate request is received. ...@@ -2244,6 +2297,106 @@ Called when an SSL client certificate request is received.
} }
``` ```
```ts
// xxx.ets API10
import web_webview from '@ohos.web.webview'
import bundle from '@ohos.bundle'
let uri = "";
export default class CertManagerService {
private static sInstance: CertManagerService;
private authUri = "";
public static getInstance(): CertManagerService {
if (CertManagerService.sInstance == null) {
CertManagerService.sInstance = new CertManagerService();
}
return CertManagerService.sInstance;
}
async grantAppPm(callback) {
let message = '';
// Note: Replace com.example.myapplication with the actual application name.
let bundleInfo = await bundle.getBundleInfo("com.example.myapplication", bundle.BundleFlag.GET_BUNDLE_DEFAULT)
let clientAppUid = bundleInfo.uid
let appUid = clientAppUid.toString()
// Note: For globalThis.AbilityContext, add globalThis.AbilityContext = this.context to the onCreate function in the MainAbility.ts file.
await globalThis.AbilityContext.startAbilityForResult(
{
bundleName: "com.ohos.certmanager",
abilityName: "MainAbility",
uri: "requestAuthorize",
parameters: {
appUid: appUid, // UID of the requesting application.
}
})
.then((data) => {
if (!data.resultCode) {
this.authUri = data.want.parameters.authUri; // Value of authUri returned when authorization is successful.
}
})
message += "after grantAppPm authUri: " + this.authUri;
uri = this.authUri;
callback(message)
}
}
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
@State message: string ='Hello World' // message is used for debugging and observation.
certManager = CertManagerService.getInstance();
build() {
Row() {
Column() {
Row() {
// Step 1: Perform authorization to obtain the URI.
Button('GrantApp')
.onClick(() => {
this.certManager.grantAppPm((data) => {
this.message = data;
});
})
// Step 2: After the authorization, in two-way authentication, the onClientAuthenticationRequest callback is used to send the URI to the web server for authentication.
Button("ClientCertAuth")
.onClick(() => {
this.controller.loadUrl('https://www.example2.com'); // Server website that supports two-way authentication.
})
}
Web({ src: 'https://www.example1.com', controller: this.controller })
.fileAccess(true)
.javaScriptAccess(true)
.domStorageAccess(true)
.onlineImageAccess(true)
.onClientAuthenticationRequest((event) => {
AlertDialog.show({
title: 'ClientAuth',
message: 'Text',
confirm: {
value: 'Confirm',
action: () => {
event.handler.confirm(uri);
}
},
cancel: () => {
event.handler.cancel();
}
})
})
}
}
.width('100%')
.height('100%')
}
}
```
### onPermissionRequest<sup>9+</sup> ### onPermissionRequest<sup>9+</sup>
onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void) onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void)
...@@ -2260,10 +2413,12 @@ Called when a permission request is received. ...@@ -2260,10 +2413,12 @@ Called when a permission request is received.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -2316,10 +2471,12 @@ Shows a context menu after the user clicks the right mouse button or long presse ...@@ -2316,10 +2471,12 @@ Shows a context menu after the user clicks the right mouse button or long presse
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -2350,10 +2507,12 @@ Called when the scrollbar of the page scrolls. ...@@ -2350,10 +2507,12 @@ Called when the scrollbar of the page scrolls.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -2383,10 +2542,12 @@ Registers a callback for receiving a request to obtain the geolocation informati ...@@ -2383,10 +2542,12 @@ Registers a callback for receiving a request to obtain the geolocation informati
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller:WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src:'www.example.com', controller:this.controller }) Web({ src:'www.example.com', controller:this.controller })
...@@ -2427,10 +2588,12 @@ Called to notify the user that the request for obtaining the geolocation informa ...@@ -2427,10 +2588,12 @@ Called to notify the user that the request for obtaining the geolocation informa
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller:WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src:'www.example.com', controller:this.controller }) Web({ src:'www.example.com', controller:this.controller })
...@@ -2459,10 +2622,12 @@ Called when the component enters full screen mode. ...@@ -2459,10 +2622,12 @@ Called when the component enters full screen mode.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller:WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
handler: FullScreenExitHandler = null handler: FullScreenExitHandler = null
build() { build() {
Column() { Column() {
...@@ -2492,10 +2657,12 @@ Called when the component exits full screen mode. ...@@ -2492,10 +2657,12 @@ Called when the component exits full screen mode.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller:WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
handler: FullScreenExitHandler = null handler: FullScreenExitHandler = null
build() { build() {
Column() { Column() {
...@@ -2525,7 +2692,7 @@ Registers a callback for window creation. ...@@ -2525,7 +2692,7 @@ Registers a callback for window creation.
| isAlert | boolean | Whether to open the target URL in a new window. The value **true** means to open the target URL in a new window, and **false** means to open the target URL in a new tab.| | isAlert | boolean | Whether to open the target URL in a new window. The value **true** means to open the target URL in a new window, and **false** means to open the target URL in a new tab.|
| isUserTrigger | boolean | Whether the creation is triggered by the user. The value **true** means that the creation is triggered by the user, and **false** means the opposite. | | isUserTrigger | boolean | Whether the creation is triggered by the user. The value **true** means that the creation is triggered by the user, and **false** means the opposite. |
| targetUrl | string | Target URL. | | targetUrl | string | Target URL. |
| handler | [ControllerHandler](#controllerhandler9) | **WebController** instance for setting the new window. | | handler | [ControllerHandler](#controllerhandler9) | **WebviewController** instance for setting the new window. |
**Example** **Example**
...@@ -2566,10 +2733,12 @@ Registers a callback for window closure. ...@@ -2566,10 +2733,12 @@ Registers a callback for window closure.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller:WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src:'www.example.com', controller: this.controller }) Web({ src:'www.example.com', controller: this.controller })
...@@ -2599,10 +2768,12 @@ Called to notify the caller of the search result on the web page. ...@@ -2599,10 +2768,12 @@ Called to notify the caller of the search result on the web page.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: WebController = new WebController() controller: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
...@@ -2791,6 +2962,40 @@ Called when this web page receives a new favicon. ...@@ -2791,6 +2962,40 @@ Called when this web page receives a new favicon.
} }
``` ```
### onAudioStateChanged<sup>10+</sup>
onAudioStateChanged(callback: (event: { playing: boolean }) => void)
Registers a callback for audio playback status changes on the web page.
**Parameters**
| Name | Type | Description |
| ------- | ---------------------------------------------- | ----------------------------------- |
| playing | boolean | Audio playback status on the current page. The value **true** means that audio is being played, and **false** means the opposite.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController()
@State playing: boolean = false
build() {
Column() {
Web({ src:'www.example.com', controller: this.controller })
.onAudioStateChanged(event => {
this.playing = event.playing
console.debug('onAudioStateChanged playing: ' + this.playing)
})
}
}
}
```
## ConsoleMessage ## ConsoleMessage
Implements the **ConsoleMessage** object. For the sample code, see [onConsole](#onconsole). Implements the **ConsoleMessage** object. For the sample code, see [onConsole](#onconsole).
...@@ -3179,6 +3384,18 @@ Instructs the **\<Web>** component to select a file. ...@@ -3179,6 +3384,18 @@ Instructs the **\<Web>** component to select a file.
Implements the **FileSelectorParam** object. For the sample code, see [onShowFileSelector](#onshowfileselector9). Implements the **FileSelectorParam** object. For the sample code, see [onShowFileSelector](#onshowfileselector9).
### getTitle<sup>9+</sup>
getTitle(): string
Obtains the title of this file selector.
**Return value**
| Type | Description |
| ------ | -------- |
| string | Title of the file selector.|
### getMode<sup>9+</sup> ### getMode<sup>9+</sup>
getMode(): FileSelectorMode getMode(): FileSelectorMode
...@@ -3289,6 +3506,18 @@ Uses the specified private key and client certificate chain. ...@@ -3289,6 +3506,18 @@ Uses the specified private key and client certificate chain.
| priKeyFile | string | Yes | File that stores the private key, which is a directory including the file name. | | priKeyFile | string | Yes | File that stores the private key, which is a directory including the file name. |
| certChainFile | string | Yes | File that stores the certificate chain, which is a directory including the file name.| | certChainFile | string | Yes | File that stores the certificate chain, which is a directory including the file name.|
### confirm<sup>10+</sup>
confirm(authUri : string): void
Instructs the **\<Web>** component to use the specified credentials (obtained from the certificate management module).
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ------------- |
| authUri | string | Yes | Key value of the credentials. |
### cancel<sup>9+</sup> ### cancel<sup>9+</sup>
cancel(): void cancel(): void
...@@ -3588,7 +3817,148 @@ Sets the geolocation permission status of a web page. ...@@ -3588,7 +3817,148 @@ Sets the geolocation permission status of a web page.
| allow | boolean | Yes | - | Geolocation permission status. | | allow | boolean | Yes | - | Geolocation permission status. |
| retain | boolean | Yes | - | Whether the geolocation permission status can be saved to the system. You can manage the geolocation permissions saved to the system through [GeolocationPermissions<sup>9+</sup>](../apis/js-apis-webview.md#geolocationpermissions).| | retain | boolean | Yes | - | Whether the geolocation permission status can be saved to the system. You can manage the geolocation permissions saved to the system through [GeolocationPermissions<sup>9+</sup>](../apis/js-apis-webview.md#geolocationpermissions).|
## WebController ## MessageLevel
| Name | Description |
| ----- | :---- |
| Debug | Debug level.|
| Error | Error level.|
| Info | Information level.|
| Log | Log level.|
| Warn | Warning level. |
## RenderExitReason
Enumerates the reasons why the rendering process exits.
| Name | Description |
| -------------------------- | ----------------- |
| ProcessAbnormalTermination | The rendering process exits abnormally. |
| ProcessWasKilled | The rendering process receives a SIGKILL message or is manually terminated.|
| ProcessCrashed | The rendering process crashes due to segmentation or other errors. |
| ProcessOom | The program memory is running low. |
| ProcessExitUnknown | Other reason. |
## MixedMode
| Name | Description |
| ---------- | ---------------------------------- |
| All | HTTP and HTTPS hybrid content can be loaded. This means that all insecure content can be loaded.|
| Compatible | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded. |
| None | HTTP and HTTPS hybrid content cannot be loaded. |
## CacheMode
| Name | Description |
| ------- | ------------------------------------ |
| Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.|
| None | The cache is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet. |
| Online | The cache is not used to load the resources. All resources are obtained from the Internet. |
| Only | The cache alone is used to load the resources. |
## FileSelectorMode
| Name | Description |
| -------------------- | ---------- |
| FileOpenMode | Open and upload a file. |
| FileOpenMultipleMode | Open and upload multiple files. |
| FileOpenFolderMode | Open and upload a folder.|
| FileSaveMode | Save a file. |
## HitTestType
| Name | Description |
| ------------- | ------------------------ |
| EditText | Editable area. |
| Email | Email address. |
| HttpAnchor | Hyperlink whose **src** is **http**. |
| HttpAnchorImg | Image with a hyperlink, where **src** is **http**.|
| Img | HTML::img tag. |
| Map | Geographical address. |
| Phone | Phone number. |
| Unknown | Unknown content. |
## SslError<sup>9+</sup>
Enumerates the error codes returned by **onSslErrorEventReceive** API.
| Name | Description |
| ------------ | ----------- |
| Invalid | Minor error. |
| HostMismatch | The host name does not match. |
| DateInvalid | The certificate has an invalid date. |
| Untrusted | The certificate issuer is not trusted.|
## ProtectedResourceType<sup>9+</sup>
| Name | Description | Remarks |
| --------- | ------------- | -------------------------- |
| MidiSysex | MIDI SYSEX resource.| Currently, only permission events can be reported. MIDI devices are not yet supported.|
## WebDarkMode<sup>9+</sup>
| Name | Description |
| ------- | ------------------------------------ |
| Off | The web dark mode is disabled. |
| On | The web dark mode is enabled. |
| Auto | The web dark mode setting follows the system settings. |
## DataResubmissionHandler<sup>9+</sup>
Implements the **DataResubmissionHandler** object for resubmitting or canceling the web form data.
### resend<sup>9+</sup>
resend(): void
Resends the web form data.
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController()
build() {
Column() {
Web({ src:'www.example.com', controller: this.controller })
.onDataResubmitted((event) => {
console.log('onDataResubmitted')
event.handler.resend();
})
}
}
}
```
### cancel<sup>9+</sup>
cancel(): void
Cancels the resending of web form data.
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController()
build() {
Column() {
Web({ src:'www.example.com', controller: this.controller })
.onDataResubmitted((event) => {
console.log('onDataResubmitted')
event.handler.cancel();
})
}
}
}
```
## WebController
Implements a **WebController** to control the behavior of the **\<Web>** component. A **WebController** can control only one **\<Web>** component, and the APIs in the **WebController** can be invoked only after it has been bound to the target **\<Web>** component. Implements a **WebController** to control the behavior of the **\<Web>** component. A **WebController** can control only one **\<Web>** component, and the APIs in the **WebController** can be invoked only after it has been bound to the target **\<Web>** component.
...@@ -3600,6 +3970,39 @@ This API is deprecated since API version 9. You are advised to use [WebviewContr ...@@ -3600,6 +3970,39 @@ This API is deprecated since API version 9. You are advised to use [WebviewContr
webController: WebController = new WebController() webController: WebController = new WebController()
``` ```
### getCookieManager<sup>9+</sup>
getCookieManager(): WebCookie
Obtains the cookie management object of the **\<Web>** component.
**Return value**
| Type | Description |
| --------- | ---------------------------------------- |
| WebCookie | Cookie management object. For details, see [WebCookie](#webcookie).|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('getCookieManager')
.onClick(() => {
let cookieManager = this.controller.getCookieManager()
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### requestFocus<sup>(deprecated)</sup> ### requestFocus<sup>(deprecated)</sup>
requestFocus() requestFocus()
...@@ -3874,39 +4277,6 @@ This API is deprecated since API version 9. You are advised to use [getHitTest<s ...@@ -3874,39 +4277,6 @@ This API is deprecated since API version 9. You are advised to use [getHitTest<s
} }
``` ```
### getTitle<sup>9+</sup>
getTitle(): string
Obtains the title of the current web page.
**Return value**
| Type | Description |
| ------ | -------- |
| string | Title of the current web page.|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('getTitle')
.onClick(() => {
let title = this.controller.getTitle()
console.log("title: " + title)
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### loadData<sup>(deprecated)</sup> ### loadData<sup>(deprecated)</sup>
loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string }) loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string })
...@@ -4303,47 +4673,15 @@ This API is deprecated since API version 9. You are advised to use [clearHistory ...@@ -4303,47 +4673,15 @@ This API is deprecated since API version 9. You are advised to use [clearHistory
} }
``` ```
### getCookieManager<sup>9+</sup> ## WebCookie<sup>(deprecated)</sup>
getCookieManager(): WebCookie
Obtains the cookie management object of the **\<Web>** component.
**Return value**
| Type | Description |
| --------- | ---------------------------------------- |
| WebCookie | Cookie management object. For details, see [WebCookie](#webcookie).|
**Example**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Button('getCookieManager')
.onClick(() => {
let cookieManager = this.controller.getCookieManager()
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
## WebCookie
Manages behavior of cookies in **\<Web>** components. All **\<Web>** components in an application share a **WebCookie**. You can use the **getCookieManager** API in **controller** to obtain the **WebCookie** for subsequent cookie management. Manages behavior of cookies in **\<Web>** components. All **\<Web>** components in an application share a **WebCookie**. You can use the **getCookieManager** API in **controller** to obtain the **WebCookie** for subsequent cookie management.
### setCookie<sup>9+</sup> ### setCookie<sup>(deprecated)</sup>
setCookie(url: string, value: string): boolean setCookie(url: string, value: string): boolean
Sets the cookie. This API returns the result synchronously. Returns **true** if the operation is successful; returns **false** otherwise. Sets the cookie. This API returns the result synchronously. Returns **true** if the operation is successful; returns **false** otherwise.
This API is deprecated since API version 9. You are advised to use [setCookie<sup>9+</sup>](../apis/js-apis-webview.md#setcookie) instead.
**Parameters** **Parameters**
...@@ -4371,7 +4709,7 @@ Sets the cookie. This API returns the result synchronously. Returns **true** if ...@@ -4371,7 +4709,7 @@ Sets the cookie. This API returns the result synchronously. Returns **true** if
Column() { Column() {
Button('setCookie') Button('setCookie')
.onClick(() => { .onClick(() => {
let result = this.controller.getCookieManager().setCookie("www.example.com", "a=b") let result = this.controller.getCookieManager().setCookie("https://www.example.com", "a=b")
console.log("result: " + result) console.log("result: " + result)
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -4379,10 +4717,11 @@ Sets the cookie. This API returns the result synchronously. Returns **true** if ...@@ -4379,10 +4717,11 @@ Sets the cookie. This API returns the result synchronously. Returns **true** if
} }
} }
``` ```
### saveCookieSync<sup>9+</sup> ### saveCookie<sup>(deprecated)</sup>
saveCookieSync(): boolean saveCookie(): boolean
Saves the cookies in the memory to the drive. This API returns the result synchronously. Saves the cookies in the memory to the drive. This API returns the result synchronously.
This API is deprecated since API version 9. You are advised to use [saveCookieAsync<sup>9+</sup>](../apis/js-apis-webview.md#savecookieasync) instead.
**Return value** **Return value**
...@@ -4401,9 +4740,9 @@ Saves the cookies in the memory to the drive. This API returns the result synchr ...@@ -4401,9 +4740,9 @@ Saves the cookies in the memory to the drive. This API returns the result synchr
build() { build() {
Column() { Column() {
Button('saveCookieSync') Button('saveCookie')
.onClick(() => { .onClick(() => {
let result = this.controller.getCookieManager().saveCookieSync() let result = this.controller.getCookieManager().saveCookie()
console.log("result: " + result) console.log("result: " + result)
}) })
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -4411,144 +4750,3 @@ Saves the cookies in the memory to the drive. This API returns the result synchr ...@@ -4411,144 +4750,3 @@ Saves the cookies in the memory to the drive. This API returns the result synchr
} }
} }
``` ```
## MessageLevel
| Name | Description |
| ----- | :---- |
| Debug | Debug level.|
| Error | Error level.|
| Info | Information level.|
| Log | Log level.|
| Warn | Warning level. |
## RenderExitReason
Enumerates the reasons why the rendering process exits.
| Name | Description |
| -------------------------- | ----------------- |
| ProcessAbnormalTermination | The rendering process exits abnormally. |
| ProcessWasKilled | The rendering process receives a SIGKILL message or is manually terminated.|
| ProcessCrashed | The rendering process crashes due to segmentation or other errors. |
| ProcessOom | The program memory is running low. |
| ProcessExitUnknown | Other reason. |
## MixedMode
| Name | Description |
| ---------- | ---------------------------------- |
| All | HTTP and HTTPS hybrid content can be loaded. This means that all insecure content can be loaded.|
| Compatible | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded. |
| None | HTTP and HTTPS hybrid content cannot be loaded. |
## CacheMode
| Name | Description |
| ------- | ------------------------------------ |
| Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.|
| None | The cache is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet. |
| Online | The cache is not used to load the resources. All resources are obtained from the Internet. |
| Only | The cache alone is used to load the resources. |
## FileSelectorMode
| Name | Description |
| -------------------- | ---------- |
| FileOpenMode | Open and upload a file. |
| FileOpenMultipleMode | Open and upload multiple files. |
| FileOpenFolderMode | Open and upload a folder.|
| FileSaveMode | Save a file. |
## HitTestType
| Name | Description |
| ------------- | ------------------------ |
| EditText | Editable area. |
| Email | Email address. |
| HttpAnchor | Hyperlink whose **src** is **http**. |
| HttpAnchorImg | Image with a hyperlink, where **src** is **http**.|
| Img | HTML::img tag. |
| Map | Geographical address. |
| Phone | Phone number. |
| Unknown | Unknown content. |
## SslError<sup>9+</sup>
Enumerates the error codes returned by **onSslErrorEventReceive** API.
| Name | Description |
| ------------ | ----------- |
| Invalid | Minor error. |
| HostMismatch | The host name does not match. |
| DateInvalid | The certificate has an invalid date. |
| Untrusted | The certificate issuer is not trusted.|
## ProtectedResourceType<sup>9+</sup>
| Name | Description | Remarks |
| --------- | ------------- | -------------------------- |
| MidiSysex | MIDI SYSEX resource.| Currently, only permission events can be reported. MIDI devices are not yet supported.|
## WebDarkMode<sup>9+</sup>
| Name | Description |
| ------- | ------------------------------------ |
| Off | The web dark mode is disabled. |
| On | The web dark mode is enabled. |
| Auto | The web dark mode setting follows the system settings. |
## DataResubmissionHandler<sup>9+</sup>
Implements the **DataResubmissionHandler** object for resubmitting or canceling the web form data.
### resend<sup>9+</sup>
resend(): void
Resends the web form data.
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController()
build() {
Column() {
Web({ src:'www.example.com', controller: this.controller })
.onDataResubmitted((event) => {
console.log('onDataResubmitted')
event.handler.resend();
})
}
}
}
```
### cancel<sup>9+</sup>
cancel(): void
Cancels the resending of web form data.
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController()
build() {
Column() {
Web({ src:'www.example.com', controller: this.controller })
.onDataResubmitted((event) => {
console.log('onDataResubmitted')
event.handler.cancel();
})
}
}
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册