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 })
}
}
}