I’m not sure if this is even a problem that needed a solution but I needed to get the source code off of an Android Emulator running version 2.3.3 and using the stock Android Browser. There isn’t a view source capability on the browser, and other methods that include displaying source code in a alert box seem didn’t seem to be useful.
a) Install Node.js. If you’re on Mac OS/X, you should use brew install node. For Windows go to http://nodejs.org/download/ grab it and install it.
Then, Start up and Setup Weinre
c) run weinre: weinre –httpPort 7897 –boundHost -all- –verbose You’ll want to give a httpPort of something that is free on your system. I happened to choose 7897
d) On your desktop browser, hit <MACHINE_ip>:7897 where machine ip is the ip address of your machine
d2) You’ll see a URL Bookmarker at the bottom. This bookmark will need to be copied Android Device browser bookmarks. Copy this into your clipboard and paste into a text editor on your desktop. Ensure that the bookmark is pointing to the IP Address of your machine. We’re going to make this as a bookmark on your emulator or device.
d3) On your desktop browser, hit <MACHINE_IP>:7897/client This brings up the debug page. Keep an eye on this page when you inject the bookmark later on. You’ll see this page magically come to life when you hit the link in your Emulator Browser.
From here on out it depends on what device type you want to prepare this with.
Either you can follow Android 2.3.3 Emulator Browser steps..
e) Open up terminal and type telnet localhost 5554 (windows syntax might be different but you’ll just need to telnet into the android device)
g) Open the Messages app. We’re going to copy the message. You’ll see a text message from 1234 there. Hover your mouse over it, hold the left mouse button down and wait for the menu to come up. Click Copy Message.
h) Go back to Android Browser. Open bookmarks, Hold the bookmark icon to add it. When Add bookmark comes up add Name as “Debug Page” and add location as the contents of the the android clip board by holding mouse down and selecting paste.
Or you can follow these steps for iPhone Emulator or Physical Device … (i’m sure it will work with 4.2.2 android)
e) On your physical device you can hit MACHINE_IP:7897
f) if you can do this then scroll to the bottom and copy the bookmark and add it to your device. Steps vary depending on the device.
Viewing the Source Code for a Page
In this next set of steps, we’ll look at the source code for any page that you hit with the Android Emulator.
i) Hit any page you want to view in the Android 2.3.3 browser emulator.
j) Now keep an eye on your desktop browser that is open to MACHINE_IP:7897/client while you do this step. On your android browser open bookmarks and click the debug page. This will inject some code into the page and make it available for Weinre to look at. You’ll notice that hopefully the page becomes triggered and sees the target debug device. What you did is send a message over to the Weinre server on your machine. This message contains the HTML page that you were viewing on the Android Emulator.
k) Go to your desktop browser and click Elements. You’ll see all the source tree for the page on the android browser.
l) Click Console and type in without the quotes ‘document.body.innerHTML’ There is your source.