. * * @var string */ const ERROR_HANDLER = 'document.querySelector("script[src*=\'/v0.js\']").onerror=function(){' . 'document.querySelector(\'style[amp-boilerplate]\').textContent=\'\'}'; /** * Apply transformations to the provided DOM document. * * @param Document $document DOM document to apply the transformations to. * @param ErrorCollection $errors Collection of errors that are collected during transformation. * @return void */ public function transform(Document $document, ErrorCollection $errors) { if ($document->html->hasAttribute(Attribute::I_AMPHTML_NO_BOILERPLATE)) { // Boilerplate was removed, so no need for the amp-onerror handler. return; } $document->head->appendChild( $document->createElementWithAttributes( Tag::SCRIPT, [ Attribute::AMP_ONERROR => null, ], self::ERROR_HANDLER ) ); } }