欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > 使用DevTools工具调试前端页面,便捷脚本,鸿蒙调试webView

使用DevTools工具调试前端页面,便捷脚本,鸿蒙调试webView

2025/5/7 19:41:36 来源:https://blog.csdn.net/weixin_42301175/article/details/147734145  浏览:    关键词:使用DevTools工具调试前端页面,便捷脚本,鸿蒙调试webView

参考官方文章

便捷脚本 创建文本,复制修改后缀为bat

建立bat文件

@echo off
setlocal enabledelayedexpansion:: Initialize port number and PID list
set PORT=9222
set PID_LIST=:: Get the list of all forwarded ports and PIDs
for /f "tokens=2,5 delims=:_" %%a in ('hdc fport ls') do (if %%a gtr !PORT! (set PORT=%%a)for /f "tokens=1 delims= " %%c in ("%%b") do (set PID_LIST=!PID_LIST! %%c)
):: Increment port number for next application
set temp_PORT=!PORT!
set /a temp_PORT+=1
set PORT=!temp_PORT!:: Get the domain socket name of devtools
for /f "tokens=*" %%a in ('hdc shell "cat /proc/net/unix | grep devtools"') do (set SOCKET_NAME=%%a:: Extract process IDfor /f "delims=_ tokens=4" %%b in ("!SOCKET_NAME!") do set PID=%%b:: Check if PID already has a mappingecho !PID_LIST! | findstr /C:" !PID! " >nulif errorlevel 1 (:: Add mappinghdc fport tcp:!PORT! localabstract:webview_devtools_remote_!PID!if errorlevel 1 (echo Error: Failed to add mapping.pauseexit /b):: Add PID to list and increment port number for next applicationset PID_LIST=!PID_LIST! !PID!set temp_PORT=!PORT!set /a temp_PORT+=1set PORT=!temp_PORT!)
):: If no process ID was found, prompt the user to open debugging in their application code and provide the documentation link
if "!SOCKET_NAME!"=="" (echo No process ID was found. Please open debugging in your application code using the corresponding interface. You can find the relevant documentation at this link: [https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/web/web-debugging-with-devtools.md]pauseexit /b
):: Check mapping
hdc fport lsecho.
echo Script executed successfully. Press any key to exit...
pause >nul:: Try to open the page in Edge
start msedge chrome://inspect/#devices.com:: If Edge is not available, then open the page in Chrome
if errorlevel 1 (start chrome chrome://inspect/#devices.com
)endlocal

调试页面

chrome://inspect/#devices

调试web页面再双击执行脚本
在这里插入图片描述
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词