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

[feature request] Support more structured logging from the browser #61

Open
shepmaster opened this issue Jun 24, 2020 · 2 comments
Open

Comments

@shepmaster
Copy link

In our application, we have a bunch of junk messages from third-party components that we can't turn off.

Sample
info: %cDownload the React DevTools for a better development experience: https://fb.me/react-devtools font-weight:bold
warning: Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.
 

 
* Move code with side effects to componentDidMount, and set initial state in the constructor.
 
* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

For our Selenium tests, we have a bit of glue code to get the browser logs and clean the things we don't care about:

errors = page.driver.browser.manage.logs.get(:browser)
errors.reject! { |e| e.message.include? 'React DevTools' }
errors.reject! { |e| e.message.match? REACT_DEPRECATED_WARNING }

The Apparition documentation states that the way to control output from console.* statements is via browser_logger, much the same as Poltergeist:

:browser_logger (IO object) - This is where your console.log statements will show up. Default: STDOUT

Unfortunately, by being IO-based, it becomes difficult to perform any filtering. For example, the write call might include data unrelated to the target message or the target message might be split into multiple calls.

Examples
write: "this is a very important message\nAnd this is a different one from React DevTools"
write: "React "
write: "DevTools"

Would it be possible to transfer these browser messages in a more structured manner so that they are easier to work with?

@twalpole
Copy link
Owner

Is #console_messages available on the Browser object what you're looking for?

@shepmaster
Copy link
Author

That does look promising, thank you! Can you point me towards the documentation I missed so I can find this kind of thing without bothering you next time?


From some experimentation:

  • #console_messages returns an array of OpenStructs with the keys [:type, :message, :source, :line_number, :columnNumber]. It's unfortunate the difference in naming style for rows and columns.

  • type appears to follow the console standard for levels — log, info, warn, error

  • The output from browser_logger still occurs when console_messages is used. Setting browser_logger to nil disables console_messages as well (it's always empty). Instead, I used File.open(File::NULL, "w").

  • It would be nice to be able to act as more of a filter. Right now, I effectively suppress all messages during the test run, then print them out as a batch at the end. This removes the ability to see how they mix with other prints (such as those in my tests)

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