How do I programmatically check if a context is active? How do I see which contexts are active on the page?  

I can't find any ContextManager object in hook_preprocess_page().
I figured it out: The Context module defines a service for getting the ContextManager object, which has getActiveContexts(). You can obtain it using the following code.

$activeContexts = \Drupal::service('context.manager')-&gt;getActiveContexts();


I need to read Service Container.