HarmonyOS webview加载页面时会加载两遍?

通过webview加载页面时会加载两遍,走两个onLoadIntercept、onPageBegin、onPageEnd,这是什么问题啊?

可以通过什么方式,让webview只走一次生命周期吗?如果不行,可以通过什么方式知道是第一次,还是第二次呢?

发现在onPageBegin中调用setCustomUserAgent导致的:

this.webviewController.setCustomUserAgent(this.userAgent)

在加载前调用setCustomUserAgent,报错:Error message:Init error. The WebviewController must be associated with a Web component

应该怎么调用setCustomUserAgent呢?

阅读 595
1 个回答

setCustomUserAgent推荐设置的位置是onControllerAttached回调事件中

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进