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

js_bridge_call: use logging instead of print() #1391

Closed
MacMoneysac666 opened this issue May 23, 2024 · 1 comment
Closed

js_bridge_call: use logging instead of print() #1391

MacMoneysac666 opened this issue May 23, 2024 · 1 comment

Comments

@MacMoneysac666
Copy link

MacMoneysac666 commented May 23, 2024

Specification

  • pywebview version: 5.1
  • operating system: Windows
  • web renderer: Chromium

Description

The function js_bridge_call uses print() if an exception occur:

def js_bridge_call(window: Window, func_name: str, param: Any, value_id: str) -> None:
    def _call():
        try:
            result = func(*func_params)
            result = json.dumps(result).replace('\\', '\\\\').replace("'", "\\'")
            code = f'window.pywebview._returnValues["{func_name}"]["{value_id}"] = {{value: \'{result}\'}}'
        except Exception as e:
            print(traceback.format_exc())
            error = {'message': str(e), 'name': type(e).__name__, 'stack': traceback.format_exc()}
            result = json.dumps(error).replace('\\', '\\\\').replace("'", "\\'")
            code = f'window.pywebview._returnValues["{func_name}"]["{value_id}"] = {{isError: true, value: \'{result}\'}}'

    ...

Imho, it would be a good idea to use logging instead. User applications in particular can make heavy use of the logging framework.

If the change is not easily possible due to backwards compatibility, it would still be great if it could be configured - e.g. via an environment variable.

I hope I haven't overlooked anything and would like to thank you for this project!

Practicalities

I am willing to work on this issue myself.

@r0x0r
Copy link
Owner

r0x0r commented May 29, 2024

Good suggestion. I pushed this change to master

@r0x0r r0x0r closed this as completed May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants