I do a lot of my dev work from mobile devices. Is there a way to get js access to console.log output from within a mobile browser?
-
Easiest to do it by connecting your device to your workstation and debugging using chrome on your workstation to debug: https://developers.google.com/web/tools/chrome-devtools/remote-debugging/ – admcfajn Nov 01 '17 at 21:50
-
1Thank you for your quick response, @admcfajn. I am aware of how to use desktop devtools for chrome via usb or wifi, however, what I am looking for is a way to get console.log output from within the mobile device itself. I do a lot of my work on my actual phone, and although tunneling a remote session and adb to my desktop from wherever I happen to be at is easy enough, working on a remote desktop session from wherever I'm at just to get the log output is not convenient if I don't have my tablet. I do a lot of work on the phone itself, and usually it's easy, sometimes I need the console. – jdmayfield Nov 02 '17 at 00:20
-
There are some sites that provide functionality like this, but I'm not a fan of dropping my code on a random person's server. Here's an example: https://jsconsole.com/ . But there's gotta be a way to do it without depending on somebody else's server. – jdmayfield Nov 02 '17 at 00:24
-
1It's phrased a little differently, but here's the best resource I've found so far: https://stackoverflow.com/questions/2314886/how-can-i-debug-javascript-on-android – admcfajn Nov 02 '17 at 06:28
-
Awesome! Thanks for the resource tip, @admcfajn. Maybe it'll lead me an easy way to locally interface with the mobile console. Easy enough fake a js console 'window' with a couple textarea's and a button to eval a command and capture "log output", but I need the unrestricted/automatic enumeration the real console object does, like when you type an object name. My site runs an ssh web terminal from a node.js https/wss server. Not sure if something on node would help, but maybe between these things there's a workable answer. Short on time today, so will check it out tonight. Thanks! – jdmayfield Nov 02 '17 at 17:59
-
Very welcome @jdmayfield here's another link: http://people.apache.org/~pmuellr/weinre/docs/latest/ – admcfajn Nov 02 '17 at 21:32
-
1I've heard you can view-source from mobile by creating a new bookmark & adding the following to the address field: `javascript:(function()%7Bvar%20a=window.open('about:blank').document;a.write('%3C!DOCTYPE%20html%3E%3Chtml%3E%3Chead%3E%3Ctitle%3ESource%20of%20'+location.href+'%3C/title%3E%3Cmeta%20name=%22viewport%22%20content=%22width=device-width%22%20/%3E%3C/head%3E%3Cbody%3E%3C/body%3E%3C/html%3E');a.close();var%20b=a.body.appendChild(a.createElement('pre'));b.style.overflow='auto';b.style.whiteSpace='pre-wrap';b.appendChild(a.createTextNode(document.documentElement.innerHTML))%7D)();` – admcfajn Nov 02 '17 at 21:32
-
Nice. So you could go to a page, then go to the bookmark and it would act like a 'view source' button. I bet you could make a simple page with a link containing it where a user could just add it to their bookmarks. Wonder if it would work on https. Also, I am thinking one way I could get unrestricted console.log enumeration is possibly to pass a js object to the server as a blob, console.log it on the server, and capture it's stdout sending it back to my client app. If I can do it client-side only though would be better. The above hack is great for getting a snapshot of the html though. – jdmayfield Nov 02 '17 at 23:19
-
Yeah, open the bookmark when viewing the page I think is how it works... Could this help expose console on the frontend of your app? https://www.npmjs.com/package/console.io – admcfajn Nov 03 '17 at 01:41
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/158126/discussion-between-admcfajn-and-jdmayfield). I think this might be the solution: https://stackoverflow.com/questions/19636423/embed-js-console-within-website – admcfajn Nov 03 '17 at 01:47
4 Answers
Currently, the best method would be to 'hook into' the native console and display the output as HTML, while still allowing the output to go to the native console.
You could implement your own version very easily....
// Reference to an output container, use 'pre' styling for JSON output
var output = document.createElement('pre');
document.body.appendChild(output);
// Reference to native method(s)
var oldLog = console.log;
console.log = function( ...items ) {
// Call native method first
oldLog.apply(this,items);
// Use JSON to transform objects, all others display normally
items.forEach( (item,i)=>{
items[i] = (typeof item === 'object' ? JSON.stringify(item,null,4) : item);
});
output.innerHTML += items.join(' ') + '<br />';
};
// You could even allow Javascript input...
function consoleInput( data ) {
// Print it to console as typed
console.log( data + '<br />' );
try {
console.log( eval( data ) );
} catch (e) {
console.log( e.stack );
}
}
....but rather than reinvent the wheel, there's a couple projects you might be interested in trying.
I'm personally using hnlDesign's mobileConsole and have been very happy with it. It's simple and just what you'd want and expect.
I recently became aware of Eruda but haven't had a chance to test it, other than playing with their demo. It implements a lot more developer tools, but for this reason might also be overkill for a lot of projects. It doesn't feel as lightweight (its file size is definitely much larger, even minified!), and if you want the breadth and intensity of developer tools, it would be better to use remote debugging. Most of us who are wanting a mobile console are just wanting the basics for quick tests and the like.

- 1,147
- 2
- 14
- 21
-
Thank you, @Marcus! I really appreciate you taking the time to shoot me an answer. It seems my questions tend to be rather esoteric or something. Anyway, really appreciate the post Yes, I just want the basic output you would get from console.log (well, in particular) with the automatic enumeration of objects etc. Did some 'console' hijacking on my own, but couldn't expand objects using the native console. Oddly, yesterday I found a site that did just that, using the browsers console object and redirecting it's output. I'll check this out, and post a link to what I found also. Thanks! – jdmayfield Jan 23 '18 at 10:16
Use Eruda, by far the best one, at least from the ones I tried.

- 141
- 1
- 6
-
Blown away. Just add these 2 lines in ANY page at the bottom: And it will work like MAGIC! It's hard to amaze me nowadays, but I am totally flabbergasted... – ZioBit Jan 20 '23 at 06:40
For Android - I found this works:
- Open Android Studio IDE
- Connecting the device in debug mode
- Open logcat
- Run the browser UI on android device - to see the console log output
Here's a few console.log() lines from logcat:
[INFO:CONSOLE(18)] "100 - checking FUNC PARAM ... ", source: https://somewhere/util/message_util.js (18)
[INFO:CONSOLE(18)] "101 - > ENTER: AppAuth.onHasAuthFunc", source: https://somewhere/util/message_util.js (18)
Idea to try this approach, thanks to @Marcus's answer , suggesting:
" 'hook into' the native console "
~~~~~~
Also, saw other posts suggesting to type: about:debug
.. into the address bar of device browser. Not sure if that had anything to do with getting the connection to work

- 11,284
- 8
- 90
- 137
-
Hmm... Interesting approach. The idea here is to be independent from another device, however; Could this be viewed from the device however, without the additional computer? Preferably from within the browser itself. On a similar note, I have seen a few native Android logcat apps, however have not had much luck with them. I so wish the Chromium guys would just make a native way to do this like you can on a PC. The information is there. We just need to see it. Sometimes you just need to code, even if all you have available is your phone. (or tablet/phablet). Full enumeration. – jdmayfield Jul 07 '18 at 07:51
-
If he could use a computer why would he code on a phone! Probably this is not anyone is gonna look at! – Charitra Agarwal Jun 26 '22 at 11:49
Chrome can debug mobile browser.
On the Android device, go to Settings > Developer options
. (Note: If you do not see Developer options
, you may need to enable it by going to About phone
and tapping Build number
seven times.)
In Developer options
, enable USB debugging
.
Connect the Android device to your computer via USB.
On your computer, open Chrome and navigate to chrome://inspect
.
You will see a list of devices. Find your device and click Inspect
next to the WebView you want to debug.
Source: https://developer.chrome.com/docs/devtools/remote-debugging/
-
While both true and notable, this still requires a desktop browser, and has already been mentioned more than once. The question is how to get identical console.log output with *only* a mobile browser by itself. – jdmayfield Jul 19 '23 at 04:51
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34705990) – Ram Chander Jul 21 '23 at 07:07