鸿蒙


如何设置调试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;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=&amp;#039; &amp;#039; read -ra parts &amp;lt;&amp;lt;&amp;lt; &amp;quot;$line&amp;quot; taskline=&amp;quot;${parts\[1\]} ${parts\[2\]}&amp;quot; \# Delete the corresponding fport rule echo &amp;quot;Removing forward rule for $taskline&amp;quot; hdc fport rm $taskline result=$? if \[ $result -eq 0 \]; then echo &amp;quot;Remove forward rule success, taskline:$taskline&amp;quot; else echo &amp;quot;Failed to remove forward rule, taskline:$taskline&amp;quot; fi done &amp;lt;&amp;lt;&amp;lt; &amp;quot;$CURRENT\_FPORT\_LIST&amp;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 &amp;#039;\_&amp;#039; &amp;#039;{print $NF}&amp;#039;) if \[ -z &amp;quot;$PID\_LIST&amp;quot; \]; then echo &amp;quot;Failed to retrieve PID from the device&amp;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 &amp;quot;Failed to execute hdc fport command&amp;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;amp;file=file.png" alt="" /></p> <h2>看到如下位置,点击打开调试工具</h2> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=cda1e52c737e525ea952d57f73734aac&amp;amp;file=file.png" alt="" /></p>

页面列表

ITEM_HTML