No javascript console in the browser
hanyu-natsu opened this issue · 7 comments
I have compiled anode with node v0.6-android, my device is a pandaboard ES running linaro android 4.1.1. The compilation was successful, and I installed the .apk in the android OS.
For testing it, I use a hello world script :
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.error('Server running at http://127.0.0.1:1337/');
I put the path to the script file in the application window and click "start", then I open my browser and tap 172.0.0.1:1337. Now the problem is that I have the 'Hello Word' message in the page without the javascript console log. I have enabled the option "show javascript console", but it doesn't appear. I can even read the console in other web pages.
So what could be the problem ?
Are you expecting the console.log to come out into the browser log or the server log?
The "Hello world" is the document returned by the server to the browser's http request, and so the browser will display this page. There's no javascript running in the returned page, so you won't see anything in the browser's javascript console.
The "console.error" statement is running on the server, so perhaps you're expecting that to come out into the logcat of the server. Unfortunately this doesn't happen automatically - console.error goes to the stderr of the application process, but by default Android just sends this to /dev/null.
You can get Android to redirect stderr and stdout to logcat if you do the following in an Android shell:
echo "log.redirect-stdio=true" > /data/local.prop
Hope this helps
thank you for your help !
I tried doing "setprop log.redirect-stdio true" in the android shell, and I have this line [log.redirect-stdio]: [true] when I run getprop.
I think I shall have the err message in my Logcat when I start the server, but nothing, here is the log :
09-25 15:46:27.235: I/ActivityManager(1647): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher u=0} from pid 1647
09-25 15:46:28.712: D/dalvikvm(1818): WAIT_FOR_CONCURRENT_GC blocked 0ms
09-25 15:46:28.767: D/dalvikvm(1818): GC_EXPLICIT freed 125K, 20% free 9015K/11207K, paused 3ms+9ms, total 51ms
09-25 15:46:30.017: I/ActivityManager(1647): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=org.meshpoint.anode/.AnodeActivity u=0} from pid 1818
09-25 15:46:30.118: D/dalvikvm(1647): GC_CONCURRENT freed 826K, 10% free 9440K/10439K, paused 5ms+0ms, total 90ms
09-25 15:46:30.134: D/dalvikvm(1647): WAIT_FOR_CONCURRENT_GC blocked 79ms
09-25 15:46:30.181: D/dalvikvm(2427): Not late-enabling CheckJNI (already on)
09-25 15:46:30.181: D/dalvikvm(1391): WAIT_FOR_CONCURRENT_GC blocked 0ms
09-25 15:46:30.181: I/ActivityManager(1647): Start proc org.meshpoint.anode for activity org.meshpoint.anode/.AnodeActivity: pid=2427 uid=10048 gids={3003, 1015, 3002, 3001, 1028}
09-25 15:46:30.243: D/dalvikvm(1391): GC_EXPLICIT freed 38K, 5% free 5984K/6275K, paused 3ms+5ms, total 62ms
09-25 15:46:30.243: D/dalvikvm(1391): WAIT_FOR_CONCURRENT_GC blocked 0ms
09-25 15:46:30.251: W/ActivityThread(2427): Application org.meshpoint.anode can be debugged on port 8100...
09-25 15:46:30.306: D/dalvikvm(1391): GC_EXPLICIT freed <1K, 5% free 5984K/6275K, paused 4ms+3ms, total 53ms
09-25 15:46:30.306: D/dalvikvm(1391): WAIT_FOR_CONCURRENT_GC blocked 0ms
09-25 15:46:30.337: D/dalvikvm(1391): GC_EXPLICIT freed <1K, 5% free 5984K/6275K, paused 2ms+2ms, total 37ms
09-25 15:46:30.454: V/TabletStatusBar(1737): setLightsOn(true)
09-25 15:46:30.548: I/ActivityManager(1647): Displayed org.meshpoint.anode/.AnodeActivity: +404ms
09-25 15:46:42.556: E/BinaryDictionaryGetter(1783): Could not find a dictionary pack
09-25 15:46:42.556: E/ActivityThread(1783): Failed to find provider info for com.android.inputmethod.latin.dictionarypack
09-25 15:46:42.610: D/dalvikvm(1783): GC_CONCURRENT freed 258K, 6% free 6427K/6791K, paused 17ms+0ms, total 59ms
09-25 15:46:52.470: V/anode::RuntimeNative(2427): extractLib: library up to date
09-25 15:46:52.470: D/dalvikvm(2427): Trying to load lib /data/data/org.meshpoint.anode/app/libjninode.so 0x415d77f0
09-25 15:46:52.478: D/dalvikvm(2427): Added shared lib /data/data/org.meshpoint.anode/app/libjninode.so 0x415d77f0
09-25 15:46:52.478: D/dalvikvm(2427): No JNI_OnLoad found in /data/data/org.meshpoint.anode/app/libjninode.so 0x415d77f0, skipping init
09-25 15:46:52.478: V/anode::RuntimeNative(2427): extractLib: library up to date
09-25 15:46:52.478: D/dalvikvm(2427): Trying to load lib /data/data/org.meshpoint.anode/node_modules/bridge.node 0x415d77f0
09-25 15:46:52.493: D/dalvikvm(2427): Added shared lib /data/data/org.meshpoint.anode/node_modules/bridge.node 0x415d77f0
09-25 15:46:52.493: D/dalvikvm(2427): No JNI_OnLoad found in /data/data/org.meshpoint.anode/node_modules/bridge.node 0x415d77f0, skipping init
09-25 15:46:52.493: V/anode::RuntimeNative(2427): init: loaded libraries: modulePath = /data/data/org.meshpoint.anode/node_modules
09-25 15:46:52.493: V/libjninode(2427): Java_org_meshpoint_anode_RuntimeNative_nodeInit: ent
09-25 15:46:52.493: V/libjninode(2427): getNativeArgs: ent
09-25 15:46:52.493: V/libjninode(2427): getNativeArgs: ret 1
09-25 15:46:52.509: V/libjninode(2427): Java_org_meshpoint_anode_RuntimeNative_nodeInit: ret
09-25 15:46:52.509: V/libjninode(2427): Java_org_meshpoint_anode_RuntimeNative_create ent
09-25 15:46:52.509: V/libjninode(2427): Java_org_meshpoint_anode_RuntimeNative_create ret
09-25 15:46:52.509: V/anode::Isolate(2427): Isolate.run(): setting context
09-25 15:46:52.509: D/dalvikvm(2427): Trying to load lib null/bridge.node 0x415d77f0
09-25 15:46:52.509: D/dalvikvm(2427): Added shared lib null/bridge.node 0x415d77f0
09-25 15:46:52.509: D/dalvikvm(2427): No JNI_OnLoad found in null/bridge.node 0x415d77f0, skipping init
09-25 15:46:52.509: V/bridge-core(2427): Java_org_meshpoint_anode_bridge_BridgeNative_setContext: ent
09-25 15:46:52.509: V/bridge-core(2427): Env::setupEnv(): ent
09-25 15:46:52.509: V/bridge-core(2427): Env::initProcess(): ent
09-25 15:46:52.509: V/bridge-core(2427): Env::initProcess(): ret
09-25 15:46:52.509: V/bridge-core(2427): Env::initThread(): ent
09-25 15:46:52.509: V/bridge-core(2427): Env::initThread(): ret
09-25 15:46:52.509: V/bridge-core(2427): Env::setupEnv(): ret
09-25 15:46:52.509: V/bridge-core(2427): Java_org_meshpoint_anode_bridge_BridgeNative_setContext: ret
09-25 15:46:52.509: V/anode::Isolate(2427): Isolate.run(): set context
09-25 15:46:52.509: V/libjninode(2427): Java_org_meshpoint_anode_RuntimeNative_start: ent
09-25 15:46:52.509: V/libjninode(2427): getNativeArgs: ent
09-25 15:46:52.509: V/libjninode(2427): getNativeArgs: ret 2
Perhaps that mechanism for setting the redirect property works only on phones and isn't enabled on your development board.
Can you try writing to a file and confirm you can see the output there?
I'm working on a new console object that will be a native node module that will write directly to logcat but maybe writing to a file will do what you need in the short term.
I tried outputting to a file, this works well using 'fs',
But for the stdio, I have these messages in my logcat :
09-27 11:17:30.945: D/AndroidRuntime(2622): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
09-27 11:17:30.945: D/AndroidRuntime(2622): CheckJNI is ON
09-27 11:17:30.960: D/dalvikvm(2622): Trying to load lib libjavacore.so 0x0
09-27 11:17:30.960: D/dalvikvm(2622): Added shared lib libjavacore.so 0x0
09-27 11:17:30.984: D/dalvikvm(2622): Trying to load lib libnativehelper.so 0x0
09-27 11:17:30.984: D/dalvikvm(2622): Added shared lib libnativehelper.so 0x0
09-27 11:17:31.312: I/ethernet(2622): Loading ethernet jni class
09-27 11:17:31.351: D/AndroidRuntime(2622): Calling main entry com.android.commands.am.Am
09-27 11:17:31.351: I/stdout(2622): Broadcasting: Intent { act=org.meshpoint.anode.START (has extras) }
09-27 11:17:31.367: I/stdout(2622): Broadcast completed: result=0
09-27 11:17:31.367: D/AndroidRuntime(2622): Shutting down VM
09-27 11:17:31.367: I/AndroidRuntime(2622): NOTE: attach of thread 'Binder_3' failed
09-27 11:17:31.367: D/dalvikvm(2622): GC_CONCURRENT freed 102K, 81% free 494K/2560K, paused 0ms+0ms, total 2ms
09-27 11:17:31.367: D/dalvikvm(2622): Debugger has detached; object registry had 1 entries
09-27 11:17:31.367: D/dalvikvm(2622): Joining stdio converter...
09-27 11:17:31.367: I/stdout(2622): Shutting down
09-27 11:17:31.367: V/libjninode(2521): Java_org_meshpoint_anode_RuntimeNative_create ent
09-27 11:17:31.367: V/libjninode(2521): Java_org_meshpoint_anode_RuntimeNative_create ret
09-27 11:17:31.375: V/anode::Isolate(2521): Isolate.run(): setting context
09-27 11:17:31.375: V/bridge-core(2521): Java_org_meshpoint_anode_bridge_BridgeNative_setContext: ent
09-27 11:17:31.375: V/bridge-core(2521): Env::setupEnv(): ent
09-27 11:17:31.375: V/bridge-core(2521): Env::initThread(): ent
09-27 11:17:31.375: V/bridge-core(2521): Env::initThread(): ret
09-27 11:17:31.375: V/bridge-core(2521): Env::setupEnv(): ret
09-27 11:17:31.375: V/bridge-core(2521): Java_org_meshpoint_anode_bridge_BridgeNative_setContext: ret
09-27 11:17:31.375: V/anode::Isolate(2521): Isolate.run(): set context
09-27 11:17:31.375: V/libjninode(2521): Java_org_meshpoint_anode_RuntimeNative_start: ent
09-27 11:17:31.375: V/libjninode(2521): getNativeArgs: ent
09-27 11:17:31.375: V/libjninode(2521): getNativeArgs: ret 2
09-27 11:17:31.710: V/libjninode(2521): Java_org_meshpoint_anode_RuntimeNative_start: ret 1
I have run my javascript with adb shell am broadcast -a org.meshpoint.anode.START -e cmdline /data/tmp/hello.js,
and I got the roadcasting: Intent { act=org.meshpoint.anode.START (has extras) } and Broadcast completed: result=0 in my logcat.
The problem seems to be in these lines :
09-27 11:17:31.367: D/AndroidRuntime(2622): Shutting down VM
09-27 11:17:31.367: I/AndroidRuntime(2622): NOTE: attach of thread 'Binder_3' failed
09-27 11:17:31.367: D/dalvikvm(2622): Debugger has detached; object registry had 1 entries
09-27 11:17:31.367: D/dalvikvm(2622): Joining stdio converter...
09-27 11:17:31.367: I/stdout(2622): Shutting down
I don't understand what AndroidRuntime was trying to do with the thread 'Binder_3'...these messages weren't there if I don't enable the log.redirect-stdio.
After working on this feature last week, I have written a native module enabling logs to logcat on C++, and I modified the console.js so that for the android system, the console will use my methods to write logs.
I insert the native module and his head into the node src, and I changed this file : <node_extensions.h> to register my module.
ok, that sounds interesting. Are you able to share the code?
I did the pull request to your node repo v0.6-android.