目录

When should the cookie of the login information be injected? How do I ensure that the login information cookie can be injected into the web page that is just opened?

Use webview.once to register a one-time callback for web events of the specified type. Generally, injection can be performed after web initialization is complete.

import { webview } from '@kit.ArkWeb'

webview.once("webInited", () => {
  console.log("setCookie");
  webview.WebCookieManager.configCookie("https://www.example.com", 'a=b,c=d,e=f');
})

@Entry
@Component
struct WebComponent {
  controller: webview.WebviewController = new webview.WebviewController();

  build() {
    Column() {
      Web({ src: 'www.example.com', controller: this.controller })
    }
  }
}