从命令行打开 Tizen Remote Web Inspector

问题描述 投票:0回答:3

我即将接管维护 Tizen 2017 js 应用程序,并且是该平台的新手。据我所知,该应用程序是在官方 Tizen IDE 之外开发的,采用基本项目的框架,并使用普通的 Web 开发工具链完成其余部分。因此,可以使用

tizen
CLI 命令安装和打开应用程序,但似乎无法使用 IDE 安装和检查(例如“运行为”/“调试为”失败)。原因。

是否可以从命令行启动远程 Web 检查器

tizen web-inspector tizen-web-app tizen-studio
3个回答
10
投票

花了很长时间才弄清楚这一点,但你可以告诉电视打开调试端口,然后使用 sdb 将其转发到本地计算机,而无需 Tizen Studio IDE。

假设 sdb 连接到电视,您可以使用以下内容

sdb shell 0 debug SomePackage.Identifier

然后拿那里返回的端口并转发它

sdb forward tcp:45087 tcp:45087

您可以在

chrome://inspect/devices#devices

找到您的可检查申请

2
投票

Chrome 开发工具

先决条件

  • Chrome 浏览器
  • 三星发展桥
  • 命令行工具

行动:

  1. 打开命令行工具(终端/命令提示符/Power Shell/Git Bash/任何你喜欢的)
  2. sdb connect 192.168.0.123
    // 三星电视 IP 地址
  3. sdb devices
    并检查您的设备是否存在
  4. 长按三星遥控器上的后退按钮,关闭三星设备上的 Telenor Stream 应用程序。
  5. 从命令行打开应用程序
    sdb shell 0 debug SomePackage.Identifier
    应该给出这个答案
    ... successfully launched pid = 15900 with debug 1 port: 37846
  6. 使用答案中的端口
    sdb forward tcp:37846 tcp:37846
  7. 在打开 Chrome 中并将
    chrome://inspect/#devices
    粘贴到地址栏中
  8. 勾选
    Discover network targets
    单击
    Configre
    并添加
    localhost:37846
  9. 确保该应用程序在您的三星上打开,它将显示为
    Remote Target
  10. 重新部署应用程序时,重复步骤 3 - 7

Chii 调试器

先决条件

行动

  1. 打开命令行工具(终端/命令提示符/Power Shell/Git Bash)
  2. 使用命令启动 Chii
    chii start -p 8080
  3. <script src="http://{your-computers-local-ip-address}:8080/target.js"></script>
    添加到index.html
  4. 将应用程序部署到三星电视并启动应用程序
  5. 打开浏览器并将
    http://localhost:8080/
    粘贴到地址栏中
  6. 点击
    Inspect

如果 index.html 中存在脚本标签,请确保您的 Chii 服务器正在运行。

如果您不使用 chii 调试器,请注释/删除 Chii 脚本。


0
投票

为后代扩展这里的答案,因为我今天一直在努力解决这个问题。

要正确且自动地启动 Chrome DevTools 窗口,需要执行以下顺序。

  1. 要终止电视上正在运行的应用程序的任何实例,请运行
    sdb shell 0 was_kill SomePackage.Identifier
  2. 要在电视上以调试模式启动应用程序,请运行
    sdb shell 0 debug SomePackage.Identifier
  3. 从输出中读取端口号(参见下面的Python脚本),我们假设它是
    ... successfully launched pid = 15900 with debug 1 port: 37846
  4. 删除所有转发端口配置
    sdb forward --remove tcp:37846
  5. 创建新的端口转发
    sdb forward tcp:37846 tcp:37846
  6. 通过解析 url 找到 devtools 窗口的正确 url
    http://localhost:37846/json
    ,提取
    json[0].devtoolsFrontendUrl
  7. 使用
    http://localhost:37846/{devtoolsFrontendUrl}
  8. 启动 Chrome

我编写了一个小的 Python 脚本,运行它来启动调试会话,这完成了所有工作并打开了一个 chrome 窗口供我调试。就像 Tizen Studio 一样。

python debug_on_tv.py --appid SomePackage.Identifier --chrome "C:\Program Files\Google\Chrome\Application\chrome.exe"

#!/usr/bin/env python
# coding=utf-8

import argparse # Command-line argument parser
import subprocess
import requests, json
import tempfile

def parseArguments():
  parser = argparse.ArgumentParser()

  parser.add_argument("--appid", help="The identifier of the tizen app",
                                 type=str)

  parser.add_argument("--chrome", help="path to chrome executable",
                                   type=str)

  return parser.parse_args()

##
## https://stackoverflow.com/a/67740138
## Note: reverse engineer the shell 0 commands from 
##       https://github.com/Samsung/Wits/blob/c18cf03eced66aa66c3603c94fccf4c14d193f00/lib/appLaunchHelper.js
def runMain():
  try:
    # Construct the argument parser for the commandline
    args = parseArguments()


    # Force a UTF8 environment for the subprocess so that files with non-ascii characters are read correctly
    # for this to work we must not use the universal line endings parameter
    my_env = os.environ
    my_env['PYTHONIOENCODING'] = 'utf-8'

    # Start by killing any processes already running
    prog_args = ['sdb']
    prog_args.append('shell')
    prog_args.append('0')
    prog_args.append('was_kill')
    prog_args.append(args.appid)
    subprocess.run(prog_args)


    # Start the app in debug mode
    prog_args = ['sdb']
    prog_args.append('shell')
    prog_args.append('0')
    prog_args.append('debug')
    prog_args.append(args.appid)
    ret = subprocess.Popen(prog_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, env=my_env)
    debugport = 0
    try:
      while True:
        try:
          line = ret.stdout.readline()
          if not line:
            break
          line = line.strip()

          # Searching for >>  ... successfully launched pid = 10422 with debug 1 port: 34187
          if 'with debug 1 port' in line:
            debugport = line[line.rfind(':')+1:].strip()
        except UnicodeDecodeError:
          continue # Ignore all unicode errors, don't care!

      # Ensure that the return code was ok before continuing
      # Check if child process has terminated. Set and return returncode attribute. Otherwise, returns None.
      retcode = ret.poll()
      while retcode is None:
        retcode = ret.poll()
    except KeyboardInterrupt:
      ret.terminate()
      raise


    # Got the debug port, kill any existing connections on this port before establishing a new one
    prog_args = ['sdb']
    prog_args.append('forward')
    prog_args.append('--remove')
    prog_args.append('tcp:{0}'.format(debugport))
    subprocess.run(prog_args)

    # Got the Debug port, now forward it
    prog_args = ['sdb']
    prog_args.append('forward')
    prog_args.append('tcp:{0}'.format(debugport))
    prog_args.append('tcp:{0}'.format(debugport))
    subprocess.run(prog_args)

    # Extract the complete debug path from the remote view
    # Idea from: https://github.com/Samsung/webIDE-common-tizentv/blob/dev/lib/appLauncher.js#L141C42-L141C47
    responseJson = json.loads(requests.get('http://localhost:{0}/json'.format(debugport)).text)
    devUrl = responseJson[0]['devtoolsFrontendUrl']

    # Start chrome, 
    # see cmd line params: https://github.com/GoogleChrome/chrome-launcher/blob/main/src/flags.ts
    prog_args = [args.chrome]
    prog_args.append('--new-window')
    prog_args.append('--no-first-run')
    prog_args.append('--disable-setuid-sandbox')
    prog_args.append('--hide-crash-restore-bubble')
    prog_args.append('--activate-on-launch')
    prog_args.append('--no-default-browser-check')
    prog_args.append('--allow-file-access-from-files')
    prog_args.append('--disable-web-security')  # This is critical, otherwise we cannot do unsecure CORS
    prog_args.append('--disable-features=Translate,OptimizationHints,MediaRouter')
    prog_args.append('--disable-extensions')
    prog_args.append('--disable-component-extensions-with-background-pages')
    prog_args.append('--disable-background-networking')
    prog_args.append('--disable-component-update')
    prog_args.append('--disable-client-side-phishing-detection')
    prog_args.append('--disable-sync')
    prog_args.append('--metrics-recording-only')
    prog_args.append('--disable-default-apps')
    prog_args.append('--disable-backgrounding-occluded-windows')
    prog_args.append('--disable-renderer-backgrounding')
    prog_args.append('--disable-background-timer-throttling')
    prog_args.append('--disable-ipc-flooding-protection')
    prog_args.append('--password-store=basic')
    prog_args.append('--force-fieldtrials=*BackgroundTracing/default/')
    prog_args.append('--use-mock-keychain')
    prog_args.append('--enable-blink-features=ShadowDOMV0,CustomElementsV0,HTMLImports') # This is done by WITS, so we do it as well
    prog_args.append('--user-data-dir={0}'.format(tempfile.TemporaryDirectory().name))   # To open a new window, # Create a temporary directory for the dummy chrome profile
    prog_args.append('--auto-open-devtools-for-tabs')
    prog_args.append('http://localhost:{0}{1}'.format(debugport,devUrl))
    subprocess.run(prog_args)

  finally:
    print("Done")

# If the script file is called by itself then execute the main function
if __name__ == '__main__':
  runMain()
© www.soinside.com 2019 - 2024. All rights reserved.