提交 29482f00 编写于 作者: C chaizhaoying 提交者: zhangjing

Web Arkts规范适配

Signed-off-by: Nchaizhaoying <chaizhaoying1@huawei.com>
上级 897d91cc
......@@ -12,12 +12,13 @@ In the following example, **createWebMessagePorts** is used to create message po
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
ports: web_webview.WebMessagePort[];
ports: web_webview.WebMessagePort[] = [];
@State sendFromEts: string = 'Send this message from ets to HTML';
@State receivedFromHtml: string = 'Display received message send from HTML';
......@@ -57,7 +58,8 @@ In the following example, **createWebMessagePorts** is used to create message po
// 3. Send the other message port (for example, port 0) to the HTML side, which then saves the message port.
this.controller.postMessage('__init_port__', [this.ports[0]], '*');
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
......@@ -71,7 +73,8 @@ In the following example, **createWebMessagePorts** is used to create message po
console.error(`ports is null, Please initialize first`);
}
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: $rawfile('xxx.html'), controller: this.controller })
......
......@@ -13,6 +13,7 @@ The following uses [setCookie()](../reference/apis/js-apis-webview.md#setcookie)
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -26,7 +27,8 @@ struct WebComponent {
try {
web_webview.WebCookieManager.setCookie('https://www.example.com', 'value=test');
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -82,6 +84,7 @@ struct WebComponent {
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -96,7 +99,8 @@ struct WebComponent {
// If this parameter is set to true, the cache in both the ROM and RAM is cleared. If this parameter is set to false, only the cache in the RAM is cleared.
this.controller.removeCache(true);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......
......@@ -12,6 +12,7 @@ In the following example, when a user clicks the **Upload** button on the fronte
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
......@@ -25,7 +26,9 @@ In the following example, when a user clicks the **Upload** button on the fronte
let fileList: Array<string> = [
'xxx/test.png',
]
event.result.handleFileList(fileList)
if (event) {
event.result.handleFileList(fileList)
}
return true;
})
}
......
......@@ -53,17 +53,23 @@ In the following example, when a user clicks the **Get Location** button on the
primaryButton: {
value: 'cancel',
action: () => {
event.geolocation.invoke(event.origin, false, false); // Deny access to the device location.
if (event) {
event.geolocation.invoke(event.origin, false, false); // Deny access to the device location.
}
}
},
secondaryButton: {
value: 'ok',
action: () => {
event.geolocation.invoke(event.origin, true, false); // Allow access to the device location.
if (event) {
event.geolocation.invoke(event.origin, true, false); // Allow access to the device location.
}
}
},
cancel: () => {
event.geolocation.invoke(event.origin, false, false); // Deny access to the device location.
if (event) {
event.geolocation.invoke(event.origin, false, false); // Deny access to the device location.
}
}
})
})
......
......@@ -16,16 +16,21 @@ The following example registers the **test()** function with the frontend page.
// xxx.ets
import web_webview from '@ohos.web.webview';
class testObj {
constructor() {
}
test(): string {
return 'ArkTS Hello World!';
}
}
@Entry
@Component
struct WebComponent {
webviewController: web_webview.WebviewController = new web_webview.WebviewController();
// Declare the object to be registered.
testObj = {
test: () => {
return 'ArkTS Hello World!';
}
}
@State testObjtest: testObj = new testObj();
build() {
Column() {
......@@ -33,7 +38,7 @@ The following example registers the **test()** function with the frontend page.
Web({ src: $rawfile('index.html'), controller: this.webviewController})
// Inject the object to the web client.
.javaScriptProxy({
object: this.testObj,
object: this.testObjtest,
name: "testObjName",
methodList: ["test"],
controller: this.webviewController
......@@ -49,19 +54,26 @@ The following example registers the **test()** function with the frontend page.
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
class testObj {
constructor() {
}
test(): string {
return "ArkUI Web Component";
}
toString(): void {
console.log('Web Component toString');
}
}
@Entry
@Component
struct Index {
webviewController: web_webview.WebviewController = new web_webview.WebviewController();
testObj = {
test: (data) => {
return "ArkUI Web Component";
},
toString: () => {
console.info('Web Component toString');
}
}
@State testObjtest: testObj = new testObj();
build() {
Column() {
......@@ -70,15 +82,17 @@ The following example registers the **test()** function with the frontend page.
try {
this.webviewController.refresh();
} catch (error) {
console.error(`Errorcode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Button('Register JavaScript To Window')
.onClick(() => {
try {
this.webviewController.registerJavaScriptProxy(this.testObj, "objName", ["test", "toString"]);
this.webviewController.registerJavaScriptProxy(this.testObjtest, "objName", ["test", "toString"]);
} catch (error) {
console.error(`Errorcode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: $rawfile('index.html'), controller: this.webviewController })
......
......@@ -31,7 +31,7 @@ In the following example, when a user clicks the **Open Page in New Window** but
.multiWindowAccess(true)
.onWindowNew((event) => {
console.info("onWindowNew...");
var popController: web_webview.WebviewController = new web_webview.WebviewController();
let popController: web_webview.WebviewController = new web_webview.WebviewController();
// Create a window, associate it with popController, and have popController returned to the Web component. If you do not need to open a new window, set the return value to event.handler.setWebController(null).
event.handler.setWebController(popController);
})
......
......@@ -19,6 +19,7 @@ In the following example, after the **www.example.com** page is loaded by the **
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -33,7 +34,8 @@ struct WebComponent {
// Upon button clicking, call loadUrl to redirect to www.example1.com.
this.webviewController.loadUrl('www.example1.com');
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
// When creating a Web component, set the default network page to be loaded to www.example.com.
......@@ -64,6 +66,7 @@ The following example shows how to load a local page file.
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -78,7 +81,8 @@ The following example shows how to load a local page file.
// Upon button clicking, call loadUrl to redirect to local1.html.
this.webviewController.loadUrl($rawfile("local1.html"));
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
// When creating a Web component, load the local.html file through $rawfile.
......@@ -111,6 +115,7 @@ The **Web** component provides the [loadData()](../reference/apis/js-apis-webvie
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -129,7 +134,8 @@ struct WebComponent {
'UTF-8'
);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
// When creating a Web component, set the default network page to be loaded to www.example.com.
......
......@@ -21,7 +21,6 @@ struct WebComponent {
.onClick(() => {
if (this.webviewController.accessBackward()) {
this.webviewController.backward();
return true;
}
})
Web({ src: 'https://www.example.com/cn/', controller: this.webviewController})
......@@ -55,11 +54,13 @@ In the following example, the frontend page **route.html** is loaded on to the a
Column() {
Web({ src: $rawfile('route.html'), controller: this.webviewController })
.onUrlLoadIntercept((event) => {
let url: string = event.data as string;
if (url.indexOf('native://') === 0) {
// Redirect to another page.
router.pushUrl({ url:url.substring(9) })
return true;
if (event) {
let url: string = event.data as string;
if (url.indexOf('native://') === 0) {
// Redirect to another page.
router.pushUrl({ url:url.substring(9) })
return true;
}
}
return false;
})
......@@ -122,18 +123,20 @@ In the following example, when a user clicks the link on the frontend page **cal
Column() {
Web({ src: $rawfile('xxx.html'), controller: this.webviewController})
.onUrlLoadIntercept((event) => {
let url: string = event.data as string;
// Check whether the link is redirecting to the dial screen of the phone app.
if (url.indexOf('tel://') === 0) {
// Redirect to the dial screen.
call.makeCall(url.substring(6), (err) => {
if (!err) {
console.info('make call succeeded.');
} else {
console.info('make call fail, err is:' + JSON.stringify(err));
}
});
return true;
if (event) {
let url: string = event.data as string;
// Check whether the link is redirecting to the dial screen of the phone app.
if (url.indexOf('tel://') === 0) {
// Redirect to the dial screen.
call.makeCall(url.substring(6), (err) => {
if (!err) {
console.info('make call succeeded.');
} else {
console.info('make call fail, err is:' + JSON.stringify(err));
}
});
return true;
}
}
return false;
})
......
......@@ -51,10 +51,12 @@ In the following example, the **Web** component intercepts the web page request
Column() {
Web({ src: $rawfile('example.html'), controller: this.controller })
.onInterceptRequest((event) => {
console.info('url:' + event.request.getRequestUrl());
// Intercept the web page request.
if (event.request.getRequestUrl() !== 'https://www.intercept.com/test.html') {
return null;
if (event) {
console.info('url:' + event.request.getRequestUrl());
// Intercept the web page request.
if (event.request.getRequestUrl() !== 'https://www.intercept.com/test.html') {
return this.responseResource;
}
}
// Construct a custom response.
this.responseResource.setResponseData(this.webData);
......
......@@ -540,7 +540,7 @@ export default class EntryAbility extends UIAbility {
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
AppStorage.set("abilityWant", want);
AppStorage.setOrCreate("abilityWant", want);
console.log("EntryAbility onCreate done")
}
}
......@@ -3881,7 +3881,7 @@ import Want from '@ohos.app.ability.Want';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
// 通过在AppStorage对象上绑定cacheDir,可以实现UIAbility组件与Page之间的数据同步。
AppStorage.set("cacheDir", this.context.cacheDir);
AppStorage.setOrCreate("cacheDir", this.context.cacheDir);
}
}
```
......@@ -3968,7 +3968,7 @@ import Want from '@ohos.app.ability.Want';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
// 通过在AppStorage对象上绑定cacheDir,可以实现UIAbility组件与Page之间的数据同步。
AppStorage.set("cacheDir", this.context.cacheDir);
AppStorage.setOrCreate("cacheDir", this.context.cacheDir);
}
}
```
......@@ -4007,8 +4007,8 @@ struct WebComponent {
try {
web_webview.WebviewController.customizeSchemes([this.scheme1, this.scheme2, this.scheme3])
} catch(error) {
let e:business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
let e:business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
}
......@@ -4493,7 +4493,7 @@ export default class EntryAbility extends UIAbility {
web_webview.WebviewController.initializeWebEngine()
// 预连接时,需要將'https://www.example.com'替换成一个真实的网站地址。
web_webview.WebviewController.prepareForPageLoad("https://www.example.com", true, 2);
AppStorage.set("abilityWant", want)
AppStorage.setOrCreate("abilityWant", want)
console.log("EntryAbility onCreate done")
}
}
......@@ -5116,6 +5116,7 @@ static deleteOrigin(origin : string): void
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5130,7 +5131,8 @@ struct WebComponent {
try {
web_webview.WebStorage.deleteOrigin(this.origin);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
......@@ -5168,6 +5170,7 @@ static getOrigins(callback: AsyncCallback\<Array\<WebStorageOrigin>>) : void
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5191,7 +5194,8 @@ struct WebComponent {
}
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
......@@ -5229,6 +5233,7 @@ static getOrigins() : Promise\<Array\<WebStorageOrigin>>
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5248,11 +5253,12 @@ struct WebComponent {
console.log('quota: ' + origins[i].quota);
}
})
.catch(e => {
.catch((e : business_error.BusinessError) => {
console.log('error: ' + JSON.stringify(e));
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
......@@ -5291,6 +5297,7 @@ static getOriginQuota(origin : string, callback : AsyncCallback\<number>) : void
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5311,7 +5318,8 @@ struct WebComponent {
console.log('quota: ' + quota);
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
......@@ -5355,6 +5363,7 @@ static getOriginQuota(origin : string) : Promise\<number>
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5371,11 +5380,12 @@ struct WebComponent {
.then(quota => {
console.log('quota: ' + quota);
})
.catch(e => {
.catch((e : business_error.BusinessError) => {
console.log('error: ' + JSON.stringify(e));
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
......@@ -5414,6 +5424,7 @@ static getOriginUsage(origin : string, callback : AsyncCallback\<number>) : void
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5434,7 +5445,8 @@ struct WebComponent {
console.log('usage: ' + usage);
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
......@@ -5478,6 +5490,7 @@ static getOriginUsage(origin : string) : Promise\<number>
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5494,11 +5507,12 @@ struct WebComponent {
.then(usage => {
console.log('usage: ' + usage);
})
.catch(e => {
.catch((e : business_error.BusinessError) => {
console.log('error: ' + JSON.stringify(e));
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
......@@ -5522,6 +5536,7 @@ static deleteAllData(): void
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5535,7 +5550,8 @@ struct WebComponent {
try {
web_webview.WebStorage.deleteAllData();
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -5579,6 +5595,7 @@ static getHttpAuthCredentials(host: string, realm: string): Array\<string>
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5586,7 +5603,7 @@ struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
host: string = "www.spincast.org";
realm: string = "protected example";
username_password: string[];
username_password: string[] = [];
build() {
Column() {
......@@ -5596,7 +5613,8 @@ struct WebComponent {
this.username_password = web_webview.WebDataBase.getHttpAuthCredentials(this.host, this.realm);
console.log('num: ' + this.username_password.length);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -5627,6 +5645,7 @@ static saveHttpAuthCredentials(host: string, realm: string, username: string, pa
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5642,7 +5661,8 @@ struct WebComponent {
try {
web_webview.WebDataBase.saveHttpAuthCredentials(this.host, this.realm, "Stromgol", "Laroche");
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -5670,6 +5690,7 @@ static existHttpAuthCredentials(): boolean
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5683,7 +5704,8 @@ struct WebComponent {
try {
let result = web_webview.WebDataBase.existHttpAuthCredentials();
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -5705,6 +5727,7 @@ static deleteHttpAuthCredentials(): void
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5718,7 +5741,8 @@ struct WebComponent {
try {
web_webview.WebDataBase.deleteHttpAuthCredentials();
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -5766,6 +5790,7 @@ static allowGeolocation(origin: string): void
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5780,7 +5805,8 @@ struct WebComponent {
try {
web_webview.GeolocationPermissions.allowGeolocation(this.origin);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -5816,6 +5842,7 @@ static deleteGeolocation(origin: string): void
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5830,7 +5857,8 @@ struct WebComponent {
try {
web_webview.GeolocationPermissions.deleteGeolocation(this.origin);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -5867,6 +5895,7 @@ static getAccessibleGeolocation(origin: string, callback: AsyncCallback\<boolean
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5887,7 +5916,8 @@ struct WebComponent {
console.log('getAccessibleGeolocationAsync result: ' + result);
});
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -5929,6 +5959,7 @@ static getAccessibleGeolocation(origin: string): Promise\<boolean>
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5944,11 +5975,12 @@ struct WebComponent {
web_webview.GeolocationPermissions.getAccessibleGeolocation(this.origin)
.then(result => {
console.log('getAccessibleGeolocationPromise result: ' + result);
}).catch(error => {
}).catch((error : business_error.BusinessError) => {
console.log('getAccessibleGeolocationPromise error: ' + JSON.stringify(error));
});
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -5976,6 +6008,7 @@ static getStoredGeolocation(callback: AsyncCallback\<Array\<string>>): void
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -5996,7 +6029,8 @@ struct WebComponent {
console.log('getStoredGeolocationAsync origins: ' + origins_str);
});
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -6024,6 +6058,7 @@ static getStoredGeolocation(): Promise\<Array\<string>>
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -6039,11 +6074,12 @@ struct WebComponent {
.then(origins => {
let origins_str: string = origins.join();
console.log('getStoredGeolocationPromise origins: ' + origins_str);
}).catch(error => {
}).catch((error : business_error.BusinessError) => {
console.log('getStoredGeolocationPromise error: ' + JSON.stringify(error));
});
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -6065,6 +6101,7 @@ static deleteAllGeolocation(): void
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
@Entry
@Component
......@@ -6078,7 +6115,8 @@ struct WebComponent {
try {
web_webview.GeolocationPermissions.deleteAllGeolocation();
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......@@ -6628,7 +6666,8 @@ getItemAtIndex(index: number): HistoryItem
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import image from "@ohos.multimedia.image"
import image from "@ohos.multimedia.image";
import business_error from '@ohos.base';
@Entry
@Component
......@@ -6646,7 +6685,8 @@ struct WebComponent {
console.log("HistoryItem: " + JSON.stringify(historyItem));
this.icon = historyItem.icon;
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册