Where in the page generation pipeline can an HTML beautifier be placed?
Yes, in advagg is a good example, you have to get the response content with $response-&gt;getContent() in a response subscriber http://cgit.drupalcode.org/advagg/tree/src/EventSubscriber/ResponseSubscriber.php?h=8.x-3.x

  public function onResponse(FilterResponseEvent $event) {
    // Only care about HTML responses.
    if (stripos($event-&gt;getResponse()-&gt;headers-&gt;get('Content-Type'), 'text/html') === FALSE) {
      return;
    }

    $response = $event-&gt;getResponse();
    $html_markup = $response-&gt;getContent();
    // modify html markup
    $response-&gt;setContent($html_markup);
  }