前言
关于“使用Devtools工具调试前端页面”,鸿蒙官网有详细文档,这里自己记录一下我是如何参照文档实现的,按照官网文档行不通可以试一下
注:我是mac系统,devecostudio版本是5.0.3.502
一、打开模拟器及Web页面
打开鸿蒙模拟器,打开对应的Web页面
二、新建脚本
根据操作系统从官网复制脚本到本地,新建.sh脚本文件(比如命名为myscript.sh)。mac脚本内容如下,windows可去官网查最新脚本
#!/bin/bash
# Initial port number
INITIAL_PORT=9222
# Get the current port number, use initial port number if not set previously
CURRENT_PORT=${PORT:-$INITIAL_PORT}
# Get the list of all PIDs that match the condition
PID_LIST=$(hdc shell cat /proc/net/unix | grep webview_devtools_remote_ | awk -F '_' '{print $NF}')
if [ -z "$PID_LIST" ]; then
echo "Failed to retrieve PID from the device"
exit 1
fi
# Increment the port number
PORT=$CURRENT_PORT
# Forward ports for each a