Each DevToolsClientImpl object contains a list of event listeners. These listeners are called when certain DevTools events occur, and can run additional code in response to those events. For example, a listener can listen for page navigation events in order to keep track of navigation status, while another listener can keep track of opening and closing of JavaScript dialog boxes, and so on.
(See Chrome Connection for more information about DevToolsClientImpl object.)
An event listener must be an object that implements the interface class DevToolsEventListener. Each listener is called in the following situations:
ConnectIfNecessary -> EnsureListenersNotifiedOfConnect -> DevToolsEventListener::OnConnected)ProcessEvent -> EnsureListenersNotifiedOfEvent -> DevToolsEventListener::OnEvent)ProcessCommandResponse -> EnsureListenersNotifiedOfCommandResponse -> DevToolsEventListener::OnCommandSuccess)The DevTools Client has three lists to keep track of listeners that still need to be notified of these three situations: DevToolsClientImpl::unnotified_connect_listeners_, DevToolsClientImpl::unnotified_event_listeners_, and DevToolsClientImpl::unnotified_cmd_response_listeners_. These lists are necessary because while a listener processes one event, it can trigger the generation of additional events.
The listeners are not notified of commands sent from ChromeDriver to DevTools.
Each instance of DevToolsClientImpl stores a list of listeners in field DevToolsClientImpl::listeners_. Listeners can be added by calling DevToolsClientImpl::AddListener.
CreateBrowserwideDevToolsClientAndConnect shortly after Chrome starts.ChromeImpl::UpdateWebViews and WebViewImpl constructor.Most listeners are added indirectly by WebViewImpl constructor. The constructor instantiates several listener objects, and the constructors for those listener objects are responsible for calling DevToolsClientImpl::AddListener to add themselves.
ChromeDriver has the following event listeners:
CastTrackerConsoleLoggerDevToolsEventsLoggerDomTrackerDownloadDirectoryOverrideManagerFrameTrackerGeolocationOverrideManagerHeapSnapshotTakerJavaScriptDialogManagerMobileEmulationOverrideManagerNavigationTrackerNetworkConditionsOverrideManagerPerformanceLoggerThe listener description below is still incomplete. More will be added in the future.
The NavigationTracker implements the wait for navigation to complete algorithm defined by the WebDriver standard. It is used when the page loading strategy is normal (the default) or eager. (When the page loading strategy is none, ChromeDriver uses NonBlockingNavigationTracker, which is not a DevTools event listener.)
NavigationTracker keeps track of the loading state of the current browsing context (either a window/tab or a frame). The loading state is represented by enum LoadingState, and can be one of three values: kUnknown, kLoading, and kNotLoading. NavigationTracker moves the loading state between these values based on the events it receives from Chrome DevTools. Most ChromeDriver commands wait for the loading state to become kNotLoading before returning.