diff --git a/phpunit.xml.dist b/phpunit.xml.dist index feb46b0..3d7f866 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ info('The public URL of the manifest file.') ->example('/site.manifest') ->end() + ->booleanNode('use_credentials') + ->defaultTrue() + ->info('Indicates whether the manifest should be fetched with credentials.') + ->end() ->scalarNode('background_color') ->info( 'The background color of the application. It should match the background-color CSS property in the sites stylesheet for a smooth transition between launching the web application and loading the site\'s content.' diff --git a/src/Subscriber/ManifestCompileEventListener.php b/src/Subscriber/ManifestCompileEventListener.php index eda62c5..dae83e6 100644 --- a/src/Subscriber/ManifestCompileEventListener.php +++ b/src/Subscriber/ManifestCompileEventListener.php @@ -10,6 +10,7 @@ use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; use Symfony\Component\Serializer\Encoder\JsonEncode; +use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; use Symfony\Component\Serializer\SerializerInterface; use const JSON_PRETTY_PRINT; @@ -40,6 +41,7 @@ public function __construct( $options = [ AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true, AbstractObjectNormalizer::SKIP_NULL_VALUES => true, + AbstractNormalizer::IGNORED_ATTRIBUTES => ['useCredentials'], JsonEncode::OPTIONS => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR, ]; if ($debug === true) { diff --git a/src/Subscriber/PwaDevServerSubscriber.php b/src/Subscriber/PwaDevServerSubscriber.php index ef76b12..74e7294 100644 --- a/src/Subscriber/PwaDevServerSubscriber.php +++ b/src/Subscriber/PwaDevServerSubscriber.php @@ -16,6 +16,7 @@ use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\Serializer\Encoder\JsonEncode; +use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; use Symfony\Component\Serializer\SerializerInterface; use function assert; @@ -69,6 +70,7 @@ public function __construct( $options = [ AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true, AbstractObjectNormalizer::SKIP_NULL_VALUES => true, + AbstractNormalizer::IGNORED_ATTRIBUTES => ['useCredentials'], JsonEncode::OPTIONS => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR, ]; if ($debug === true) { diff --git a/src/Twig/PwaRuntime.php b/src/Twig/PwaRuntime.php index e55388c..e3ca916 100644 --- a/src/Twig/PwaRuntime.php +++ b/src/Twig/PwaRuntime.php @@ -56,8 +56,12 @@ public function load( private function injectManifestFile(string $output): string { $url = $this->assetMapper->getPublicPath($this->manifestPublicUrl) ?? $this->manifestPublicUrl; + $useCredentials = ''; + if ($this->manifest->useCredentials === true) { + $useCredentials = ' crossorigin="use-credentials"'; + } - return $output . sprintf('%s', PHP_EOL, $url); + return $output . sprintf('%s', PHP_EOL, $useCredentials, $url); } private function injectThemeColor(string $output, bool $themeColor): string diff --git a/tests/autoload.php b/tests/autoload.php new file mode 100644 index 0000000..552064b --- /dev/null +++ b/tests/autoload.php @@ -0,0 +1,9 @@ +