Skip to content

Instantly share code, notes, and snippets.

@bootstraponline
Last active January 3, 2016 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bootstraponline/8412352 to your computer and use it in GitHub Desktop.
Save bootstraponline/8412352 to your computer and use it in GitHub Desktop.
# 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