flutter_js icon indicating copy to clipboard operation
flutter_js copied to clipboard

Enable capturing of console.log output

Open deva666 opened this issue 2 years ago • 1 comments

Currently, all console.log calls are relayed to the Dart print function. Most of the time this is fine, but there are some use cases where we need to do something with console.log output.

deva666 avatar Nov 07 '22 10:11 deva666

temporary solution, works on flutter_js: 0.8.0

final runtime = getJavascriptRuntime();

dynamic logFn(dynamic args) {
  // do what you want
}


// register channel callback
final channelCallbacks = JavascriptRuntime.channelFunctionsRegistered[runtime.getEngineInstanceId()];
channelCallbacks!["ConsoleLog"] = logFn;

Hope this helps.

yeliulee avatar Sep 02 '23 06:09 yeliulee