Frontend Request 

Extension key

frontend_request

Package name

maxserv/frontend-request

Version

2.0

Language

en

Author

MaxServ

License

This document is published under the Open Publication License.

Rendered

Tue, 05 May 2026 15:06:31 +0000


This extension helps you to handle frontend requests in TYPO3 from within the backend. It provides a javascript module that you can import in your own extension's javascript and based on parameters like the page id, language, and more, it returns a JSON object with the page information, such as the page title, description, and more.

This extension is not useful on its own, but it is meant to be used in combination with other extensions that need to handle frontend requests in the backend, such as Yoast SEO for TYPO3, which uses this extension to analyze the page content and provide analysis and suggestions for improving the page's SEO and readability.


Table of Contents:

What does it do? 

This extension provides a simple way to handle frontend requests in TYPO3 from within the backend. It allows you to retrieve page information such as title, description, and more based on parameters like page id and language. This is particularly useful for extensions that need to analyze frontend content,such as SEO tools.

This extension does not do anything on its own but is designed to be used in conjunction with other extensions that require frontend request handling.

It provides a JavaScript module that can be imported into your own extension's JavaScript files.

Contribution 

Anyone is welcome to contribute to Frontend Request.

There are various ways you can contribute:

  • Raise an issue on GitHub.
  • Create a pull request with your bug fixes or new features.
  • Improve this documentation via the "Edit on GitHub" workflow.

Please read the guidelines on how to contribute to this repository and how to report bugs.

Installation guide 

Install the extension using your preferred method.

Head over to your CLI and run the following command

composer require maxserv/frontend-request
Copied!

Not using composer? Download the zip file from the TER and upload it through the Extension Manager.

Javascript 

Javascript module 

This extension provides a Javascript module that you can import in your own Javascript code to make the request and get the parsed page response.

The FrontendRequest class provides a request method which expects an object with the following properties:

  • pageId: The ID of the page you want to request.
  • languageId: The ID of the language you want to request the page in.
  • additionalGetVars: (optional) A string with the additional get parameters to be sent with the request.

Example usage:

import FrontendRequest from "@maxserv/frontend-request/frontend-request.js"

class YourJavascriptClass {
    async fetchPage(pageId, languageId) {
        FrontendRequest.request({
            pageId: pageId,
            languageId: languageId,
        }).then((response) => {
            // Handle the response here
            console.log(response);
        }).catch((error) => {
            // Handle any errors here
            console.error(error);
        })
    }
}
Copied!

Fire event to listen to 

The FrontendRequest class also has a method requestWithEvent which you can call from within PHP to fire an event that can be listened to in your JavaScript code.

An example using the JavascriptRenderer within the PageRenderer:

$pageRenderer->getJavaScriptRenderer()->addJavaScriptModuleInstruction(
    JavaScriptModuleInstruction::create('@maxserv/frontend-request/frontend-request.js')->invoke(
        'requestWithEvent',
        [
            'pageId' => $pageId,
            'languageId' => $languageId,
            'additionalGetVars' => $additionalGetVars ?? '',
        ],
        'your-event-name'
    )
);
Copied!

This will fire an event with the name your-event-name that you can listen to in your JavaScript code.

document.addEventListener('your-event-name', (event) => {
    // Handle the event here
    console.log(event.detail);
});
Copied!

PageParser 

The PageParser is responsible for parsing the frontend response and transforming it into a JSON object.

The default parsers are:

  • body: Has the complete body of the page.
  • title: Contains the title of the page.
  • metadata: Contains all the metatags of the page, structured by name and content.
  • locale: Contains the locale of the page.
  • url: Contains the URL of the page.
  • favicon: Contains the URL of the favicon of the page.

Adding your own parser 

If you want to add your own parser, you can do so by adding a class which implements the ParserInterface:

<?php

namespace Vendor\Extension\Parser;

use MaxServ\FrontendRequest\Dto\RequestContext;
use MaxServ\FrontendRequest\PageParser\ParserInterface;

class MyCustomParser implements ParserInterface
{
    public function getIdentifier():  string
    {
        return 'custom_key'; // This will be the key used in the response
    }

    public function parse(string $html, RequestContext $context): string
    {
        // Your custom parsing logic goes here.
        return 'Parsed content';
    }
}
Copied!

And registering it with the correct tag in your Services.yaml:

services:
    Vendor\Extension\Parser\MyCustomParser:
        tags: [ 'frontend_request.page_parser' ]
Copied!

Overriding a parser 

If you want to override an existing parser, you can follow the same steps as above, but make sure to use the same identifier as the parser you want to override.

Be sure to add this extension as a dependency in your composer.json file to ensure correct loading order.

Events 

Event to change the URL to request 

By default the extension is generating the URL to analyse based on the Site Configuration and configured Route Enhancers. In some cases you want to change the URL that needs to be analysed.

With the ModifyPreviewUrlEvent you will be able to alter the URL that will be used to analyse your content.

First you need to create an EventListener that will handle the event:

<?php

namespace Vendor\Package\EventListener;

use MaxServ\FrontendRequest\Event\ModifyUrlEvent;

final class ModifyUrlEventEventListener
{
    public function __invoke(ModifyUrlEvent $event)
    {
        $url = $event->getUrl();
        $site = $event->getSite();
        $parameters = $event->getParameters();

        // Create a new url based on your needs

        $event->setUrl($newUrl);
    }
}
Copied!

Event to change the request 

The request is generated with the RequestFactory from TYPO3.

With the ModifyRequest you will be able to change the request, this makes it possible to (f.e.) add your own headers to the request.

First you need to create an EventListener that will handle the event:

<?php

namespace Vendor\Package\EventListener;

use MaxServ\FrontendRequest\Event\ModifyRequestEvent;

final class ModifyRequestEventListener
{
    public function __invoke(ModifyRequestEvent $event)
    {
        $request = $event->getRequest();
        $context = $event->getContext();

        $event->setRequest(
            $request->withHeader('X-Your-Own-Header', GeneralUtility::hmac(
                $context->getUrl()
            ))
        );
    }
}
Copied!

Registering an Event Listener 

After you created an event listener, you need to register it.

Check the TYPO3 documentation for your used TYPO3 version on how to register this correctly.

After you have registered the listener, you need to clear the TYPO3 cache through the Maintenance module (or vendor/bin/typo3 cache:flush) before your code will be activated.

Sitemap