如何设置调试webview里的网页
<h1>1.启动app</h1>
<p>运行app直到打开的网页</p>
<h1>2.运行脚本</h1>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=b759d0d3b90325288e893a8dae98a15a&amp;file=file.png" alt="" /></p>
<h2>mac机器</h2>
<h3>配置环境</h3>
<p>找到hdc所在的位置
编辑在~/.zshrc,在尾部添加如下代码。其中路径以您的DevEco安装实际路径为准
HDC_SDK_PATH=/Applications/DevEco-Studio.app/Contents/sdk/default/openharmony/toolchains/</p>
<pre><code>launchctl setenv HDC_SDK_PATH $HDC_SDK_PATH # 仅MacOS需要在此执行,Linux无须执行
export PATH=$PATH:$HDC_SDK_PATH</code></pre>
<h3>配置脚本</h3>
<p>mac机器是在/Users/hanhui/hongmeng.sh</p>
<pre><code>#!/bin/bash
\# Get current fport rule list
CURRENT\_FPORT\_LIST=$(hdc fport ls)
\# Delete the existing fport rule one by one
while IFS= read -r line; do
\# Extract the taskline
IFS=&#039; &#039; read -ra parts &lt;&lt;&lt; &quot;$line&quot;
taskline=&quot;${parts\[1\]} ${parts\[2\]}&quot;
\# Delete the corresponding fport rule
echo &quot;Removing forward rule for $taskline&quot;
hdc fport rm $taskline
result=$?
if \[ $result -eq 0 \]; then
echo &quot;Remove forward rule success, taskline:$taskline&quot;
else
echo &quot;Failed to remove forward rule, taskline:$taskline&quot;
fi
done &lt;&lt;&lt; &quot;$CURRENT\_FPORT\_LIST&quot;
\# 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 &#039;\_&#039; &#039;{print $NF}&#039;)
if \[ -z &quot;$PID\_LIST&quot; \]; then
echo &quot;Failed to retrieve PID from the device&quot;
exit 1
fi
\# Increment the port number
PORT=$CURRENT\_PORT
\# Forward ports for each application one by one
for PID in $PID\_LIST; do
\# Increment the port number
PORT=$((PORT + 1))
\# Execute the hdc fport command
hdc fport tcp:$PORT localabstract:webview\_devtools\_remote\_$PID
\# Check if the command executed successfully
if \[ $? -ne 0 \]; then
echo &quot;Failed to execute hdc fport command&quot;
exit 1
fi
done
\# List all forwarded ports
hdc fport ls</code></pre>
<h1>3.在chrome里运行</h1>
<p>chrome://inspect/#devices</p>
<h2>设置下监听端口</h2>
<p>这个操作只是初始时候设置一次,其他时间不用设置。
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=0e6e3e75a02f1caa85c96f9fc1574f4c&amp;file=file.png" alt="" /></p>
<h2>看到如下位置,点击打开调试工具</h2>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=cda1e52c737e525ea952d57f73734aac&amp;file=file.png" alt="" /></p>