1# Web Subsystem Changelog
2
3Compared with earlier versions, OpenHarmony 3.2.10.7 has the following API changes in its web subsystem:
4
5## cl.web.1 HitTestTypeV9 Name Change
6
7Renamed the enum class **HitTestTypeV9** **WebHitTestType** to meet the naming conventions.
8
9**Change Impact**
10
11The enum class **HitTestTypeV9** and APIs that use **HitTestTypeV9** as a parameter or return value cannot be used in OpenHarmony 3.2.10.7 and later versions.
12
13**Key API/Component Changes**
14
15- Involved APIs:
16
17  enum HitTestTypeV9
18
19- Before change:
20
21  ```ts
22  enum HitTestTypeV9
23  ```
24
25- After change:
26
27  ```ts
28  enum WebHitTestType
29  ```
30
31**Adaptation Guide**
32
33Replace **HitTestTypeV9** with **WebHitTestType**.
34
35## cl.web.2 HeaderV9 Name Change
36
37Renamed the struct **HeaderV9** **WebHeader** to meet the naming conventions.
38
39**Change Impact**
40
41The struct **HeaderV9** and APIs that use **HeaderV9** as a parameter or return value cannot be used in OpenHarmony 3.2.10.7 and later versions.
42
43**Key API/Component Changes**
44
45- Involved APIs:
46
47  interface HeaderV9
48
49- Before change:
50
51  ```ts
52  interface HeaderV9
53  ```
54
55- After change:
56
57  ```ts
58  interface WebHeader
59  ```
60
61**Adaptation Guide**
62
63Replace **HeaderV9** with **WebHeader**.
64
65## cl.web.3 Member Change of HitTestValue
66
67Rename the member variable **HitTestTypeV9** in the **HitTestValue** struct **WebHitTestType** to meet the naming conventions.
68
69**Change Impact**
70
71The struct **HitTestValue** and APIs that use **HitTestValue** as a parameter or return value cannot be used in OpenHarmony 3.2.10.7 and later versions.
72
73**Key API/Component Changes**
74
75- Involved APIs:
76
77  interface HitTestValue
78
79- Before change:
80
81  ```ts
82  interface HitTestValue {
83
84    /**
85      * Get the hit test type.
86      *
87      * @since 9
88      */
89    type: HitTestTypeV9;
90
91    /**
92      * Get the hit test extra data.
93      *
94      * @since 9
95      */
96    extra: string;
97  }
98  ```
99
100- After change:
101
102  ```ts
103  interface HitTestValue {
104
105    /**
106      * Get the hit test type.
107      *
108      * @since 9
109      */
110    type: WebHitTestType;
111
112    /**
113      * Get the hit test extra data.
114      *
115      * @since 9
116      */
117    extra: string;
118  }
119  ```
120
121**Adaptation Guide**
122
123Replace **HitTestTypeV9** with **WebHitTestType**.
124
125## cl.web.4 Parameter Type Change of loadUrl
126
127Changed the type of the **headers** parameter in **loadUrl** to **WebHeader** to meet the naming conventions.
128
129**Change Impact**
130
131The **loadUrl** API that uses the **headers** parameter cannot be used in OpenHarmony 3.2.10.7 and later versions.
132
133**Key API/Component Changes**
134
135- Involved APIs:
136
137  loadUrl(url: string | Resource, headers?: Array\<HeaderV9>): void
138
139- Before change:
140
141  ```ts
142  loadUrl(url: string | Resource, headers?: Array<HeaderV9>): void
143  ```
144
145- After change:
146
147  ```ts
148  loadUrl(url: string | Resource, headers?: Array<WebHeader>): void
149  ```
150
151**Adaptation Guide**
152
153Change the type of the **headers** parameter in **loadUrl** from **HeaderV9** to **WebHeader**.
154
155## cl.web.5 Return Value Type Change of getHitTest
156
157Changed the return value type of the **getHitTest** API to **WebHitTest** to meet the naming conventions.
158
159**Change Impact**
160
161The **getHitTest** API cannot be used in OpenHarmony 3.2.10.7 and later versions.
162
163**Key API/Component Changes**
164
165- Involved APIs:
166
167  getHitTest(): HitTestTypeV9
168
169- Before change:
170
171  ```ts
172  getHitTest(): HitTestTypeV9
173  ```
174
175- After change:
176
177  ```ts
178  getHitTest(): WebHitTestType
179  ```
180
181**Adaptation Guide**
182
183Change the return value type of the **getHitTest** API from **HitTestTypeV9** to **WebHitTestType**.
184
185## cl.web.6 Moving of the WebMessagePort Class
186
187Moved the **WebMessagePort** class to **@ohos.web.webview.d.ts** and added error throwing.
188
189**Change Impact**
190
191If your application is developed based on earlier versions, note that the **d.ts** file storage location and the name of the module to be imported are changed. In addition, be mindful of the error codes now that the APIs in the class support error code processing.
192
193**Key API/Component Changes**
194
195- Involved APIs:
196
197  postMessageEvent(message: WebMessageEvent): void;
198  onMessageEvent(callback: (result: string) => void): void;
199
200- Before change:
201
202  ```ts
203  postMessageEvent(message: WebMessageEvent): void;
204  onMessageEvent(callback: (result: string) => void): void;
205  ```
206
207- After change:
208
209  ```ts
210  postMessageEvent(message: WebMessage): void;
211  onMessageEvent(callback: (result: WebMessage) => void): void;
212  ```
213
214**Adaptation Guide**
215
216Instead of importing APIs from the original **WebMessagePort** class, import APIs from **@ohos.web.webview** as follows:
217
218  ```ts
219  import web_webview from '@ohos.web.webview';
220  ```
221
222## cl.web.7 Moving of the HitTestValue Class
223
224Moved the **HitTestValue** class to **@ohos.web.webview.d.ts**; changed **HitTestValue** from a class to an API; changed the **getType** and **getExtra** from APIs to attributes.
225
226**Change Impact**
227
228If your application is developed based on earlier versions, note that the **d.ts** file storage location and the name of the module to be imported are changed.
229
230**Key API/Component Changes**
231
232- Involved APIs:
233
234  getType(): HitTestType;
235  getExtra(): string;
236
237- Before change:
238
239  ```ts
240  getType(): HitTestType;
241  getExtra(): string;
242  ```
243
244- After change:
245
246  ```ts
247  type: WebHitTestType;
248  extra: string;
249  ```
250
251**Adaptation Guide**
252
253Instead of importing APIs from the original **HitTestValue** class, import APIs from **@ohos.web.webview** as follows:
254
255  ```ts
256  import web_webview from '@ohos.web.webview';
257  ```
258
259## cl.web.8 Moving of API Version 9 APIs Under WebCookie
260
261Moved APIs of API version 9 in the **WebCookie** class to **web.webview.webview.WebCookieManager**
262and added error throwing.
263
264**Change Impact**
265
266If your application is developed based on earlier versions, note that the **d.ts** file storage location and the name of the module to be imported are changed. In addition, be mindful of the error codes now that the APIs in the class support error code processing.
267The APIs in the class are static.
268
269**Key API/Component Changes**
270
271- Involved APIs:
272
273  isCookieAllowed(): boolean;
274  isThirdPartyCookieAllowed(): boolean;
275  putAcceptCookieEnabled(accept: boolean): void;
276  putAcceptThirdPartyCookieEnabled(accept: boolean): void;
277  setCookie(url: string, value: string): boolean;
278  saveCookieSync(): boolean;
279  getCookie(url: string): string;
280  existCookie(): boolean;
281  deleteEntireCookie(): void;
282  deleteSessionCookie(): void;
283
284- Before change:
285
286  ```ts
287  isCookieAllowed(): boolean;
288  isThirdPartyCookieAllowed(): boolean;
289  putAcceptCookieEnabled(accept: boolean): void;
290  putAcceptThirdPartyCookieEnabled(accept: boolean): void;
291  setCookie(url: string, value: string): boolean;
292  saveCookieSync(): boolean;
293  getCookie(url: string): string;
294  existCookie(): boolean;
295  deleteEntireCookie(): void;
296  deleteSessionCookie(): void;
297  ```
298
299- After change:
300
301  ```ts
302  static isCookieAllowed(): boolean;
303  static isThirdPartyCookieAllowed(): boolean;
304  static putAcceptCookieEnabled(accept: boolean): void;
305  static putAcceptThirdPartyCookieEnabled(accept: boolean): void;
306  static setCookie(url: string, value: string): void;
307  static saveCookieAsync(): Promise<void>;
308  static saveCookieAsync(callback: AsyncCallback<void>): void;
309  static getCookie(url: string): string;
310  static existCookie(): boolean;
311  static deleteEntireCookie(): void;
312  static deleteSessionCookie(): void;
313  ```
314
315**Adaptation Guide**
316
317Instead of importing APIs from the original **WebCookie** class, import APIs from **@ohos.web.webview** as follows:
318
319  ```ts
320  import web_webview from '@ohos.web.webview';
321  ```
322
323## cl.web.9 Moving of API Version 9 APIs Under WebController
324
325Moved APIs of API version 9 in the **WebController** class to **web.webview.webview.WebviewController** and added error throwing.
326
327**Change Impact**
328
329If your application is developed based on earlier versions, note that the **d.ts** file storage location and the name of the module to be imported are changed. In addition, be mindful of the error codes now that the APIs in the class support error code processing.
330The **getDefaultUserAgent** API is renamed **getUserAgent**.
331
332**Key API/Component Changes**
333
334- Involved APIs:
335
336  zoomIn(): boolean;
337  zoomOut(): boolean;
338  createWebMessagePorts(): Array\<WebMessagePort>;
339  postMessage(options: { message: WebMessageEvent, uri: string}): void;
340  getHitTestValue(): HitTestValue;
341  getWebId(): number;
342  getDefaultUserAgent(): string;
343  getTitle(): string;
344  getPageHeight(): number;
345  backOrForward(step: number): void;
346  searchAllAsync(searchString: string): void;
347  clearMatches(): void;
348  searchNext(forward: boolean): void;
349  clearSslCache(): void;
350  clearClientAuthenticationCache(): void;
351  getUrl(): string;
352
353- Before change:
354
355  ```ts
356  zoomIn(): boolean;
357  zoomOut(): boolean;
358  createWebMessagePorts(): Array<WebMessagePort>;
359  postMessage(options: { message: WebMessageEvent, uri: string}): void;
360  getHitTestValue(): HitTestValue;
361  getWebId(): number;
362  getDefaultUserAgent(): string;
363  getTitle(): string;
364  getPageHeight(): number;
365  backOrForward(step: number): void;
366  searchAllAsync(searchString: string): void;
367  clearMatches(): void;
368  searchNext(forward: boolean): void;
369  clearSslCache(): void;
370  clearClientAuthenticationCache(): void;
371  getUrl(): string;
372  ```
373
374- After change:
375
376  ```ts
377  zoomIn(): void;
378  zoomOut(): void;
379  createWebMessagePorts(): Array<WebMessagePort>;
380  postMessage(name: string, ports: Array<WebMessagePort>, uri: string): void;
381  getHitTestValue(): HitTestValue;
382  getWebId(): number;
383  getUserAgent(): string;
384  getTitle(): string;
385  getPageHeight(): number;
386  backOrForward(step: number): void;
387  searchAllAsync(searchString: string): void;
388  clearMatches(): void;
389  searchNext(forward: boolean): void;
390  clearSslCache(): void;
391  clearClientAuthenticationCache(): void;
392  getUrl(): string;
393  ```
394
395**Adaptation Guide**
396
397Instead of importing APIs from the original **WebController** class, import APIs from **@ohos.web.webview** as follows:
398
399  ```ts
400  import web_webview from '@ohos.web.webview';
401  ```
402
403## cl.web.10 Moving of the WebAsyncController Class
404
405Moved the APIs in the **WebAsyncController** class to the **web.webview.webview.WebviewController** class and added error throwing.
406
407**Change Impact**
408
409If your application is developed based on earlier versions, pay attention to error code processing.
410
411**Key API/Component Changes**
412
413- Involved APIs:
414
415  storeWebArchive(baseName: string, autoName: boolean): Promise\<string>;
416  storeWebArchive(baseName: string, autoName: boolean, callback : AsyncCallback\<string>): void;
417
418- Before change:
419
420  ```ts
421  storeWebArchive(baseName: string, autoName: boolean): Promise<string>;
422  storeWebArchive(baseName: string, autoName: boolean, callback : AsyncCallback<string>): void;
423  ```
424
425- After change:
426
427  ```ts
428  storeWebArchive(baseName: string, autoName: boolean): Promise<string>;
429  storeWebArchive(baseName: string, autoName: boolean, callback : AsyncCallback<string>): void;
430  ```
431
432**Adaptation Guide**
433
434Example:
435
436  ```ts
437  // xxx.ets
438  import web_webview from '@ohos.web.webview'
439
440  @Entry
441  @Component
442  struct WebComponent {
443    controller: web_webview.WebviewController = new web_webview.WebviewController();
444
445    build() {
446      Column() {
447        Button('saveWebArchive')
448          .onClick(() => {
449            try {
450              this.controller.storeWebArchive("/data/storage/el2/base/", true, (error, filename) => {
451                if (error) {
452                  console.info(`save web archive error: ` + JSON.stringify(error))
453                  return;
454                }
455                if (filename != null) {
456                  console.info(`save web archive success: ${filename}`)
457                }
458              });
459            } catch (error) {
460              console.error(`ErrorCode: ${error.code},  Message: ${error.message}`);
461            }
462          })
463        Web({ src: 'www.example.com', controller: this.controller })
464      }
465    }
466  }
467  ```
468