symfony(3.4) how to generate route for A2HS webmanifest

I am trying to generate a webmanifest through symfony (for the purpose of installing page as app A2HS, following this guide

<link rel="manifest" href="mysite/1/AD1/manifest.webmanifast">

This is my route configuration (also tried switching the ‘.webmanifest’ for ‘.json’, same results):

  path:     /{id}/{positionName}/manifest.{_format}
  defaults: { _controller: PoslogBundle:Entry:webmanifest, _format: webmanifest }
      _format:  webmanifest
      title:     .+

If I copypaste the manifest route into a new browser tab I get my json nicely printed
enter image description here

    "background_color": "purple",
    "description": "Positionslogg AD1",
    "display": "fullscreen",
    "icons": [
            "src": "images/appicon.png",
            "sizes": "192x192",
            "type": "image/png"
    "name": "Positionslogg AD1",
    "short_name": "AD1",
    "start_url": "mysite/app_dev.php/positionlog/1"

That url also works in the browser new tab with a .manifest at the end (http://localhost/webtools/web/app_dev.php/positionlog/1/AD1/manifest.webmanifest)

But when the browser attempts to fetch it as a manifest it appears as an empty file, the console just says

Manifest: Line: 1, column: 1, Syntax error.

1:1 Site cannot be installed: Manifest could not be fetched, is empty,
or could not be parsed

enter image description here

The controller generating the output looks like this

public function webmanifestAction($id,$positionName)

    $path = $this->generateUrl( 'poslog_index', ['id' => $id] );

    $icon = array();        
    $icon[0]["src"] = "images/appicon.png";
    $icon[0]["sizes"] = "192x192";
    $icon[0]["type"] = "image/png";

    $o = array();

    $o['background_color'] = "purple";
    $o["description"] = "Positionslogg " . $positionName;
    $o["display"] = "fullscreen";
    $o["icons"] = $icon;
    $o["name"] = "Positionslogg " . $positionName;
    $o["short_name"] = $positionName;
    $o["start_url"] = $path;
    $json = json_encode($o, JSON_PRETTY_PRINT);

    return new Response(
    array('content-type' => 'application/manifest+json'));


I’ve also tried having the response delivered as

array('content-type' => 'text/plain'));

array('content-type' => 'text/html'));

array('content-type' => 'application/json'));

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *