Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do you think it's possible to catch console output? #5

Closed
ghost opened this issue Oct 9, 2018 · 9 comments
Closed

Do you think it's possible to catch console output? #5

ghost opened this issue Oct 9, 2018 · 9 comments

Comments

@ghost
Copy link

ghost commented Oct 9, 2018

Thanks for your work.

I would like to test this, but, the question in title is also interesting to me :)

@pichillilorenzo
Copy link
Owner

Yeah I think it is possible!

For Android it is very simple: I need to add the onConsoleMessage method.

For iOS I think I can use something like:
https://stackoverflow.com/a/33751939/4637638
https://stackoverflow.com/a/49148633/4637638

@ghost
Copy link
Author

ghost commented Oct 9, 2018

That sounds great for me :) what do you think about timing? This year, ore morely unknown?

Thanks for fast response 👍

pichillilorenzo added a commit that referenced this issue Oct 9, 2018
…t a return value, added InAppBrowser.onConsoleMessage() method to manage console messages #5
@pichillilorenzo
Copy link
Owner

@flddr released new version 0.2.1! Now you can use and overidde the onConsoleMessage method to listen console messages coming from the webview.

Quick example:

class MyInAppBrowser extends InAppBrowser {

  @override
  Future onLoadStop(String url) async {
    // console messages
    await this.injectScriptCode("console.log({'testObject': 5});"); // the message will be: [object Object]
    await this.injectScriptCode("console.log('testObjectStringify', JSON.stringify({'testObject': 5}));"); // the message will be: testObjectStringify {"testObject": 5}
    await this.injectScriptCode("console.error('testError', false);"); // the message will be: testError false
  }

  @override
  void onConsoleMessage(ConsoleMessage consoleMessage) {
    print("""
    console output:
      sourceURL: ${consoleMessage.sourceURL}
      lineNumber: ${consoleMessage.lineNumber}
      message: ${consoleMessage.message}
      messageLevel: ${consoleMessage.messageLevel}
    """);
  }

}

You can find the example in the README.md file 😄

@ghost
Copy link
Author

ghost commented Oct 10, 2018

Wow! Unbelievable 💯

Thank you very much 🤗

@ghost
Copy link
Author

ghost commented Oct 10, 2018

Can i ask you another question? I am figuring out if it is possible in flutter to build a dev tool with control over complete request structure and i want to get raw response as string or byte[] before it`s consumed by dart parser. Do you have an idea; maybe, in combination with your plugin? :)

@pichillilorenzo
Copy link
Owner

@flddr I think that something could be done

@ghost
Copy link
Author

ghost commented Oct 12, 2018

@pichillilorenzo i tried to get some info here dart-lang/http#207 but actually not... I am newbie to dart, so just looking if it could be a good idea...

What do you think?

Thank you :)

@pichillilorenzo
Copy link
Owner

So you need to use the Socket class! In this way I think you could manage raw requests/responses! See this example: https://stackoverflow.com/questions/51077233/how-can-i-use-socket-in-flutter-app

@iampato iampato mentioned this issue Mar 7, 2020
@DowsingUK DowsingUK mentioned this issue Apr 29, 2020
This was referenced Jul 6, 2020
plateaukao pushed a commit to plateaukao/flutter_inappwebview that referenced this issue Jul 27, 2020
@pawangjain pawangjain mentioned this issue Jan 21, 2021
5 tasks
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant