This should be done in the upper layer. Not the base layer.
See T175092: Determine if .navboxes should be stripped from the page content delivered by the Mobile Content Service and Page Content Service for details on how this is done in MobileFrontend