HarmonyOS鸿蒙Next中ArkWeb浏览某些网站提示错误,如百度云无法提取等
HarmonyOS鸿蒙Next中ArkWeb浏览某些网站提示错误,如百度云无法提取等
ArkWeb 浏览某些网站提示错误,如百度云无法提取等。即便开启 .domStorageAccess(true) 也无济于事。
如:在版权登记网站登录时:
在百度网盘提取(使用手机 UA)时:
代码仓库:https://gitee.com/awa_Liny/LinysBrowser_NEXT
Web 组件摘要:
ForEach(this.bunch_of_tabs.Labels, (Label: tab_label) => {
Column() {
Web({
src: this.src_of_tab_index(Label.index_key),
controller: this.bunch_of_tabs.Tabs[Label.index_key] !== undefined
? this.bunch_of_tabs.Tabs[Label.index_key].controller
: undefined,
// renderMode: RenderMode.SYNC_RENDER
})// Main WEB
.width("100%")
.height("100%")
.backgroundColor('transparent')
.databaseAccess(true)
.javaScriptAccess(this.my_js(Label.index_key))
.imageAccess(this.my_image(Label.index_key))
.onlineImageAccess(this.my_image(Label.index_key))
.fileAccess(true)
.domStorageAccess(true)
.multiWindowAccess(true)
.mixedMode(MixedMode.All)
.allowWindowOpenMethod(true)
.onSearchResultReceive((result) => { ... })
.onWindowNew((event) => {
let new_target_url = event.targetUrl;
console.log('[meowWebView] New tab in new window!')
this.new_tab_gateway = new_target_url;
event.handler.setWebController(null);
})
.onErrorReceive((e) => {
if (e) {
console.error("[ArkWeb][ERROR] " + e.error.getErrorCode() + ", " + e.error.getErrorInfo()
+ " @ " + this.tab_urls[Label.index_key])
// Log web errors
}
})
.onPageBegin(() => {
console.log("[Meow][ArkWeb] on page begin");
// bind blob download delegate
this.bunch_of_downloads.init_blob_delegate();
this.bunch_of_tabs.Tabs[Label.index_key].controller.setDownloadDelegate(this.blob_delegate);
if (Label.index_key >= this.bunch_of_tabs.get_tabs_count()) {
// If not synced, idk why but o(=•ェ•=)m
return;
}
// Update History
this.current_accessBackward = this.bunch_of_tabs.Tabs[Label.index_key].controller.accessBackward()
this.current_accessForward = this.bunch_of_tabs.Tabs[Label.index_key].controller.accessForward()
// Ask tab to update its info (Reset)
this.bunch_of_tabs.Tabs[Label.index_key].update_title()
this.bunch_of_tabs.Tabs[Label.index_key].update_url()
this.bunch_of_tabs.Tabs[Label.index_key].update_is_loading(true)
this.bunch_of_tabs.Tabs[Label.index_key].update_loading_progress(0)
// Get synced lists
this.sync_list_info()
// Update Input Search Box
this.update_current_info()
this.update_search_box_text(this.current_url)
})
.onPageEnd(() => {
// console.log("[Meow][ArkWeb] on page end")
this.bunch_of_tabs.Tabs[Label.index_key].update_title();
this.bunch_of_tabs.Tabs[Label.index_key].update_url();
this.bunch_of_tabs.Tabs[Label.index_key].update_is_loading(false);
this.tab_is_loading = this.bunch_of_tabs.get_all_is_loading();
this.update_current_info();
// Save browse history if is neither resource tab nor a recovery tab
if (this.collect_new_history
&& !this.bunch_of_tabs.Tabs[Label.index_key].restore_on_creation
&& !this.tab_urls[Label.index_key].includes("resource://")
) {
let new_record = new history_record(this.tab_titles[Label.index_key], this.tab_urls[Label.index_key])
this.bunch_of_history.add_history(new_record, true, true);
} else {
this.bunch_of_tabs.Tabs[Label.index_key].restore_on_creation = false;
// log
if (!this.collect_new_history) {
console.log("[meowWebView] Didn't save history for settings disabled.");
} else {
console.log("[meowWebView] Didn't save history for a recovery process in progress")
}
}
this.determine_extra_background();
})
.onProgressChange((event) => {
if (!event) {
return;
}
let progress: number = event.newProgress;
// console.log("[Meow][ArkWeb] on progress change: " + progress.toString())
// Update current loading progress
if (progress == 0) {
return;
}
if (Label.index_key >= this.bunch_of_tabs.get_tabs_count()) {
// If not synced, idk why but o(=•ェ•=)m
return;
}
this.bunch_of_tabs.Tabs[Label.index_key].update_title()
this.bunch_of_tabs.Tabs[Label.index_key].update_url()
this.bunch_of_tabs.Tabs[Label.index_key].update_loading_progress(progress)
// Ask tab to update its info
this.sync_list_info()
// Get synced lists
this.update_current_info()
// Update Input Search Box
this.update_search_box_text(this.current_url)
if (this.bunch_of_tabs.Tabs[Label.index_key].restore_on_creation) {
return;
}
// Get web_state
let web_state = this.bunch_of_tabs.Tabs[Label.index_key].controller.serializeWebState();
// Sync to bunch_of_tabs
this.bunch_of_tabs.Tabs[Label.index_key].web_state_array = web_state;
// save web state to sandbox storage
if (web_state && !this.bunch_of_tabs.Tabs[Label.index_key].restore_on_creation) {
let identifier = "continue/continue_tabs_web_state_array_" + Label.index_key.toString();
sandbox_save(identifier, web_state.buffer);
}
})
.onDownloadStart((event) => { ... })
.onFullScreenEnter((event) => { ... })
.onFullScreenExit(() => { ... })
.onControllerAttached(async () => {
// Set UA
if (this.now_global_custom_UA != "") {
this.bunch_of_tabs.Tabs[Label.index_key].controller.setCustomUserAgent(this.now_global_custom_UA);
}
// Set Ads Blocker
console.log('[Meow][meowWebView] enableAdsBlock: ' + (this.use_adblock ? 'true' : 'false'))
this.bunch_of_tabs.Tabs[Label.index_key].controller.enableAdsBlock(this.use_adblock);
// TODO: Find out why this doesn't work sometimes for a recovered webpage :O getting crazy
// Set Ads Blocker exception list
try {
console.log('[Meow][meowWebView] add Ads Blocker Exceptions success. Operated by meowWebView ~')
webview.AdsBlockManager.addAdsBlockDisallowedList(this.adsBlocker_exceptions);
} catch (e) {
console.error('[ERROR][Meow][meowWebView] add Ads Blocker Exceptions error: ' + e);
}
// Set intelligent tracking prevention
this.bunch_of_tabs.Tabs[Label.index_key].controller.enableIntelligentTrackingPrevention(this.intelligent_tracking_prevention);
console.log('[Meow][meowWebView] ArkWeb Intelligent Tracking Prevention '
+ this.intelligent_tracking_prevention.toString() + '!');
// Restore Web State
setTimeout(() => {
if (this.bunch_of_tabs.Tabs[Label.index_key].restore_on_creation) {
if (Label.index_key < this.restore_web_state_arrays.length) {
this.bunch_of_tabs.restore_web_state(this.restore_web_state_arrays[Label.index_key],
Label.index_key);
} else {
console.error('[ERROR][Meow][meowWebView] Restore web state failed '
+'for an out-of-bound index in restore_web_state_arrays.')
}
}
}, 0)
})
.darkMode(WebDarkMode.Auto)// Dark mode!
.forceDarkAccess(this.web_force_dark_mode)// Force dark mode
.onLoadIntercept((event) => {
if (event) {
let url: string = event.data.getRequestUrl();
let match_domain_result = match_domain(url);
if (viewable_domains().includes(match_domain_result[0])) {
// Viewable
return false;
} else {
// Not viewable, perhaps is a link that can jump?
this.potential_jump_link = url;
this.woofLinkJumper_control.open();
return true;
}
}
return false;
})
.onPermissionRequest((event) => {
if (!event) {
return;
}
this.onPermit = () => {
event.request.grant(event.request.getAccessibleResource());
}
this.onDeny = () => {
event.request.deny();
}
this.ask_resources = event.request.getAccessibleResource();
this.source = event.request.getOrigin();
console.log('[Meow][meowWebView] Requesting Protected Resources: ' + event.request.getAccessibleResource());
if (this.ask_resources.length == 1 && this.ask_resources[0] == 'TYPE_SENSOR') {
// TODO: work out a workable permission manager!
this.onPermit();
console.log('[Meow][meowWebView] Permitted TYPE_SENSOR automatically!');
return;
}
this.woofWantProtectedResources_control.open();
})
.onClientAuthenticationRequest((event) => {
console.log('[meowWebView] onClientAuthenticationRequest event.host: ' + event.host);
console.log('[meowWebView] onClientAuthenticationRequest event.port ' + event.port);
console.log('[meowWebView] onClientAuthenticationRequest event.keyTypes: ' + event.keyTypes.join('\n'));
console.log('[meowWebView] onClientAuthenticationRequest event.issuers: ' + event.issuers.join('\n'));
})
} // Webs
.borderColor(this.color_current_secondary)
.borderWidth(this.border_width_tab(this.current_sub_tab_index == Label.index_key))
.width(this.current_sub_tab_index < 0 ? "100%" : this.width_tab())
.height(this.current_sub_tab_index < 0 ? "100%" : this.height_tab())
.alignRules(this.current_main_tab_index == Label.index_key ? this.align_rules_main_tab() : this.align_rules_sub_tab())
.visibility(this.my_visibility(Label.index_key))
.animation(this.tab_animation)
}, (Label: tab_label) => Label.timestamp.toString())
感谢各路大神出手相助!
更多关于HarmonyOS鸿蒙Next中ArkWeb浏览某些网站提示错误,如百度云无法提取等的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
鸿蒙Next中ArkWeb浏览网站出现错误可能由以下原因导致:
- 网站未适配ArkWeb内核
- 鸿蒙Next与ArkWeb的版本兼容性问题
- 网站安全证书不兼容
- ArkWeb的JS引擎执行差异
针对百度云无法提取的具体情况:
- 百度云前端可能使用了不兼容ArkWeb的特定API
- 文件提取功能可能依赖未完全支持的Web特性
- 跨域请求处理存在差异
临时解决方案可尝试:
- 清除ArkWeb缓存
- 开启ArkWeb的兼容模式
- 检查HarmonyOS系统更新
更多关于HarmonyOS鸿蒙Next中ArkWeb浏览某些网站提示错误,如百度云无法提取等的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
根据问题描述和代码分析,ArkWeb在访问百度云等网站时出现错误,可能涉及以下几个关键点:
- 用户代理(UA)问题:
- 虽然代码中设置了自定义UA(setCustomUserAgent),但百度云等网站对移动端UA检测较严格,建议检查实际生效的UA字符串是否符合预期
- 可尝试使用标准Chrome移动端UA测试
- 存储权限问题:
- 虽然已开启domStorageAccess(true),但百度云可能依赖其他存储机制
- 可尝试同时启用fileAccess(true)和databaseAccess(true)
- HTTPS证书校验:
- 错误截图显示安全连接问题,可能是证书校验失败
- 检查mixedMode设置是否允许加载混合内容(当前设置为MixedMode.All)
- 建议增加调试:
- 在onErrorReceive回调中打印完整的错误码和描述
- 检查onPermissionRequest是否收到资源请求被拒绝的情况
- 百度云特定问题:
- 百度云前端可能检测浏览器特性,可尝试:
.javaScriptAccess(true) .onControllerAttached(() => { controller.setWebAllowJsAccess(true); controller.setWebViewRenderMode(RenderMode.SYNC_RENDER); })
这些修改可能有助于解决网站兼容性问题,但具体效果需根据实际错误情况验证。