【问题标题】:Can not debug service-worker on an Android phone无法在 Android 手机上调试 service-worker
【发布时间】:2020-10-11 15:36:51
【问题描述】:

我有一个从我的桌面提供的带有 Service Worker 的网络应用,我想在 Android 手机 (Pixel3) 上进行调试。
在桌面上,我安装了一个自信任 CA 以满足安全连接 (https),​​并且页面显示为带有安全挂锁 - 很好!。

但在电话中,我无法显示安全挂锁。
(我可以通过 USB 数据线连接手机来调试网络应用程序,在chrome://inspect/#devices 中为所需选项卡、Pixel 3 XL 设备选择 inspect,然后与 Chrome 上的页面交互手机并在桌面上查看更改,但无法获取安全挂锁)。

为了满足安全连接,我尝试做以下事情:

  • 按照debugging on device的说明进行操作

  • 使用说明herehere在手机上安装自信任CA
    我安装了自信任 CA myCA.pem(这是通过 Security -> Install certificates -> myCA.pem 签署在桌面上使用的网站证书的同一自信任 CA,并验证它安装在 Trusted credentials -> User -> myCA 中)

  • 在 chrome devtools 中设置端口转发,并使用来自 herehere 的指令通过 localhost 访问网站。

    1. 在 chrome devtools 上,我通过 chrome://inspect/#devices -> port forwarding -> 8086 localhost:443 设置端口转发
    2. 在手机上我通过Network and Internet -> Wi-Fi -> current network -> Proxy -> Manual -> Proxy hostname: localhost, Proxy port: 8086设置代理
    3. 在手机上打开页面localhost:8086https:\\localhost:8086(页面显示挂锁不安全警告)
      页面显示挂锁不安全警告
    4. (在桌面上https://localhost 显示安全挂锁)
  • 在 chrome devtools 中设置端口转发,在您的设备上配置代理设置,映射到自定义本地域,并通过自定义域访问网站:mydomain,按照here 中的说明进行操作

    1. 在 chrome devtools 上,我通过 chrome://inspect/#devices -> port forwarding -> 8086 mydomain:443 设置端口转发
    2. 在手机上我通过Network and Internet -> Wi-Fi -> current network -> Proxy -> Manual -> Proxy hostname: localhost, Proxy port: 8086设置代理
    3. 在手机上打开页面localhost:8086https:\\localhost:8086
      页面显示不安全挂锁警告
    4. (在桌面上https://mydomain 显示安全挂锁)
  • 通过以下设置放松手机安全连接的要求:

    1. chrome://flags/#allow-insecure-localhost启用

    2. chrome://flags/#insecure origins treated as secure 启用
      http://192.168.1.74, http://mydomain, http://localhost
      (标志#insecure origins treated as secure 在桌面上运行时甚至没有帮助,我收到如下错误: DOMException: Failed to register a ServiceWorker for scope ('https://192.168.1.74/') with script ('https://192.168.1.74/sw.js'): An SSL certificate error occurred when fetching the script.

这些都没有帮助。在手机的 chrome 选项卡中,我不断看到不安全连接的三角形图标。

桌面: Ubuntu 18.04,Chrome 版本 83.0.4103.61
Pixel 3 XL: Chrome:83.0.4103.106,Android 版本 10

谢谢
阿夫纳

【问题讨论】:

    标签: android ssl service-worker


    【解决方案1】:

    我能够在 Android 手机上使用 Service Worker 远程调试 Web 应用程序,方法是:

    • Web 服务器配置设置:
      • 禁用 https
      • 使用非标准端口启用 http 服务
      • 禁用 http 到 https 的重定向
    • 在桌面上的 Chrome 和 Android 手机中设置 chrome 标志:Insecure origins treated as secure

    详情请见here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      • 1970-01-01
      • 2020-10-14
      • 2017-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多