Last active
January 3, 2016 04:58
-
-
Save bootstraponline/8412352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find open webviews on API 19 Android emulator. | |
def print_webviews | |
webviews = `adb shell cat /proc/net/unix` | |
webview_prefix = '@webview_devtools_remote_' | |
webviews = webviews.split("\r\n").reject { |l| ! l.include?(webview_prefix) } | |
# one pid may have many webviews | |
pids = webviews.map { |view| view.split(webview_prefix).last }.uniq | |
r = [] | |
pids.each { |pid| r << [ pid_to_package(pid), pid ] } | |
r | |
end | |
def pid_to_package pid | |
ps = `adb shell ps`.split("\r\n").reject { |l| ! l.include?(pid) } | |
ps.first.split(' ').last | |
end | |
# [['com.my.app', '2373']] | |
print_webviews | |
# todo: what address is the webview using? | |
# https://github.com/mirrors/chromium/blob/master/chrome/browser/devtools/android_device.cc | |
# https://github.com/mirrors/chromium/blob/master/chrome/browser/devtools/port_forwarding_controller.cc | |
# https://github.com/mirrors/chromium/blob/master/chrome/browser/devtools/devtools_adb_bridge_browsertest.cc | |
# the pid is listed in jdwp output | |
# adb jdwp | |
# attempt connecting to the unix socket | |
# local port, remote_abstract | |
# src/chrome/test/chromedriver/chrome/adb_impl.cc | |
# adb forward tcp:8000 localabstract:4558 | |
require 'socket' | |
socket = TCPSocket.open('localhost', 4594); | |
socket.print "GET /json HTTP/1.1\r\n\r\n"; | |
socket.read |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment