Enable Console and Runtime outputs only when debugging

When capturing a page, we receive a LOT of messages from chrome.
Examining these message, we see that we can reduce them a bit to speed
up Brozzler.

We always use `Console.enable` which returns all browser console output.
Also, we always use `Runtime.enable`. Doc says:
https://chromedevtools.github.io/devtools-protocol/1-3/Runtime#method-enable

Enables reporting of execution contexts creation by means of
executionContextCreated event. When the reporting gets enabled the event
will be sent immediately for each existing execution context.

These outputs are useful when debugging but not in production.
If we disable them, we reduce the websocket traffic and improve
performance. With this PR, we enable them only when the current logging
level is `DEBUG`.

Counting the number of messages before and after the change, we see
improvements like:

https://www.gnome.org/technologies/ 220 -> 202 messages.

https://www.whitehouse.gov/issues/budget-spending/  203 -> 189 messages
This commit is contained in:
Vangelis Banos 2019-09-27 13:24:06 +00:00
parent 7273c7c3a2
commit fed5e6b741

View File

@ -349,6 +349,10 @@ class Browser:
# tell browser to send us messages we're interested in # tell browser to send us messages we're interested in
self.send_to_chrome(method='Network.enable') self.send_to_chrome(method='Network.enable')
self.send_to_chrome(method='Page.enable') self.send_to_chrome(method='Page.enable')
# Enable Console & Runtime output only when debugging.
# After all, we just print these events with debug(), we don't use
# them in Brozzler logic.
if self.logger.isEnabledFor(logging.DEBUG):
self.send_to_chrome(method='Console.enable') self.send_to_chrome(method='Console.enable')
self.send_to_chrome(method='Runtime.enable') self.send_to_chrome(method='Runtime.enable')
self.send_to_chrome(method='ServiceWorker.enable') self.send_to_chrome(method='ServiceWorker.enable')