77use Gotenberg \Exceptions \NativeFunctionErrored ;
88use Gotenberg \Gotenberg ;
99use Gotenberg \Modules \ChromiumCookie ;
10+ use Gotenberg \Modules \ChromiumEmulatedMediaFeatures ;
1011use Gotenberg \Modules \ChromiumPdf ;
1112use Gotenberg \SplitMode ;
1213use Gotenberg \Stream ;
@@ -21,6 +22,7 @@ final class ChromiumPdfTest extends TestCase
2122{
2223 /**
2324 * @param ChromiumCookie[] $cookies
25+ * @param ChromiumEmulatedMediaFeatures[] $emulatedMediaFeatures
2426 * @param array<string,string> $extraHttpHeaders
2527 * @param int[] $failOnHttpStatusCodes
2628 * @param int[] $failOnResourceHttpStatusCodes
@@ -54,6 +56,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_url_en
5456 string |null $ waitForExpression = null ,
5557 string |null $ waitForSelector = null ,
5658 string |null $ emulatedMediaType = null ,
59+ array $ emulatedMediaFeatures = [],
5760 array $ cookies = [],
5861 string |null $ userAgent = null ,
5962 array $ extraHttpHeaders = [],
@@ -97,6 +100,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_url_en
97100 $ waitForExpression ,
98101 $ waitForSelector ,
99102 $ emulatedMediaType ,
103+ $ emulatedMediaFeatures ,
100104 $ cookies ,
101105 $ userAgent ,
102106 $ extraHttpHeaders ,
@@ -146,6 +150,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_url_en
146150 $ waitForExpression ,
147151 $ waitForSelector ,
148152 $ emulatedMediaType ,
153+ $ emulatedMediaFeatures ,
149154 $ cookies ,
150155 $ userAgent ,
151156 $ extraHttpHeaders ,
@@ -191,6 +196,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_url_en
191196 * string|null,
192197 * string|null,
193198 * string|null,
199+ * array<int, ChromiumEmulatedMediaFeatures>,
194200 * array<int, ChromiumCookie>,
195201 * string|null,
196202 * array<string, string>,
@@ -238,6 +244,10 @@ public static function provideUrlData(): array
238244 "window.status === 'ready' " ,
239245 '#id ' ,
240246 'print ' ,
247+ [
248+ new ChromiumEmulatedMediaFeatures ('prefers-color-scheme ' , 'dark ' ),
249+ new ChromiumEmulatedMediaFeatures ('prefers-reduced-motion ' , 'reduce ' ),
250+ ],
241251 [
242252 new ChromiumCookie ('yummy_cookie ' , 'choco ' , 'theyummycookie.com ' ),
243253 new ChromiumCookie ('vanilla_cookie ' , 'vanilla ' , 'theyummycookie.com ' , '/ ' , true , true , 'Lax ' ),
@@ -273,6 +283,7 @@ public static function provideUrlData(): array
273283
274284 /**
275285 * @param ChromiumCookie[] $cookies
286+ * @param ChromiumEmulatedMediaFeatures[] $emulatedMediaFeatures
276287 * @param array<string,string> $extraHttpHeaders
277288 * @param int[] $failOnHttpStatusCodes
278289 * @param int[] $failOnResourceHttpStatusCodes
@@ -306,6 +317,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_html_e
306317 string |null $ waitForExpression = null ,
307318 string |null $ waitForSelector = null ,
308319 string |null $ emulatedMediaType = null ,
320+ array $ emulatedMediaFeatures = [],
309321 array $ cookies = [],
310322 string |null $ userAgent = null ,
311323 array $ extraHttpHeaders = [],
@@ -349,6 +361,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_html_e
349361 $ waitForExpression ,
350362 $ waitForSelector ,
351363 $ emulatedMediaType ,
364+ $ emulatedMediaFeatures ,
352365 $ cookies ,
353366 $ userAgent ,
354367 $ extraHttpHeaders ,
@@ -400,6 +413,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_html_e
400413 $ waitForExpression ,
401414 $ waitForSelector ,
402415 $ emulatedMediaType ,
416+ $ emulatedMediaFeatures ,
403417 $ cookies ,
404418 $ userAgent ,
405419 $ extraHttpHeaders ,
@@ -445,6 +459,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_html_e
445459 * string|null,
446460 * string|null,
447461 * string|null,
462+ * array<int, ChromiumEmulatedMediaFeatures>,
448463 * array<int, ChromiumCookie>,
449464 * string|null,
450465 * array<string, string>,
@@ -492,6 +507,10 @@ public static function provideHtmlData(): array
492507 "window.status === 'ready' " ,
493508 '#id ' ,
494509 'screen ' ,
510+ [
511+ new ChromiumEmulatedMediaFeatures ('prefers-color-scheme ' , 'dark ' ),
512+ new ChromiumEmulatedMediaFeatures ('prefers-reduced-motion ' , 'reduce ' ),
513+ ],
495514 [
496515 new ChromiumCookie ('yummy_cookie ' , 'choco ' , 'theyummycookie.com ' ),
497516 new ChromiumCookie ('vanilla_cookie ' , 'vanilla ' , 'theyummycookie.com ' , '/ ' , true , true , 'Lax ' ),
@@ -527,6 +546,7 @@ public static function provideHtmlData(): array
527546
528547 /**
529548 * @param ChromiumCookie[] $cookies
549+ * @param ChromiumEmulatedMediaFeatures[] $emulatedMediaFeatures
530550 * @param array<string,string> $extraHttpHeaders
531551 * @param int[] $failOnHttpStatusCodes
532552 * @param int[] $failOnResourceHttpStatusCodes
@@ -562,6 +582,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_markdo
562582 string |null $ waitForExpression = null ,
563583 string |null $ waitForSelector = null ,
564584 string |null $ emulatedMediaType = null ,
585+ array $ emulatedMediaFeatures = [],
565586 array $ cookies = [],
566587 string |null $ userAgent = null ,
567588 array $ extraHttpHeaders = [],
@@ -605,6 +626,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_markdo
605626 $ waitForExpression ,
606627 $ waitForSelector ,
607628 $ emulatedMediaType ,
629+ $ emulatedMediaFeatures ,
608630 $ cookies ,
609631 $ userAgent ,
610632 $ extraHttpHeaders ,
@@ -661,6 +683,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_markdo
661683 $ waitForExpression ,
662684 $ waitForSelector ,
663685 $ emulatedMediaType ,
686+ $ emulatedMediaFeatures ,
664687 $ cookies ,
665688 $ userAgent ,
666689 $ extraHttpHeaders ,
@@ -707,6 +730,7 @@ public function it_creates_a_valid_request_for_the_forms_chromium_convert_markdo
707730 * string|null,
708731 * string|null,
709732 * string|null,
733+ * array<int, ChromiumEmulatedMediaFeatures>,
710734 * array<int, ChromiumCookie>,
711735 * string|null,
712736 * array<string, string>,
@@ -763,6 +787,10 @@ public static function provideMarkdownData(): array
763787 "window.status === 'ready' " ,
764788 '#id ' ,
765789 'screen ' ,
790+ [
791+ new ChromiumEmulatedMediaFeatures ('prefers-color-scheme ' , 'dark ' ),
792+ new ChromiumEmulatedMediaFeatures ('prefers-reduced-motion ' , 'reduce ' ),
793+ ],
766794 [
767795 new ChromiumCookie ('yummy_cookie ' , 'choco ' , 'theyummycookie.com ' ),
768796 new ChromiumCookie ('vanilla_cookie ' , 'vanilla ' , 'theyummycookie.com ' , '/ ' , true , true , 'Lax ' ),
@@ -798,6 +826,7 @@ public static function provideMarkdownData(): array
798826
799827 /**
800828 * @param ChromiumCookie[] $cookies
829+ * @param ChromiumEmulatedMediaFeatures[] $emulatedMediaFeatures
801830 * @param array<string,string> $extraHttpHeaders
802831 * @param int[] $failOnHttpStatusCodes
803832 * @param int[] $failOnResourceHttpStatusCodes
@@ -829,6 +858,7 @@ private function hydrateChromiumPdfFormData(
829858 string |null $ waitForExpression = null ,
830859 string |null $ waitForSelector = null ,
831860 string |null $ emulatedMediaType = null ,
861+ array $ emulatedMediaFeatures = [],
832862 array $ cookies = [],
833863 string |null $ userAgent = null ,
834864 array $ extraHttpHeaders = [],
@@ -920,6 +950,10 @@ private function hydrateChromiumPdfFormData(
920950 $ chromium ->emulateScreenMediaType ();
921951 }
922952
953+ if (count ($ emulatedMediaFeatures ) > 0 ) {
954+ $ chromium ->emulatedMediaFeatures ($ emulatedMediaFeatures );
955+ }
956+
923957 if (count ($ cookies ) > 0 ) {
924958 $ chromium ->cookies ($ cookies );
925959 }
@@ -993,6 +1027,7 @@ private function hydrateChromiumPdfFormData(
9931027
9941028 /**
9951029 * @param ChromiumCookie[] $cookies
1030+ * @param ChromiumEmulatedMediaFeatures[] $emulatedMediaFeatures
9961031 * @param array<string,string> $extraHttpHeaders
9971032 * @param int[] $failOnHttpStatusCodes
9981033 * @param int[] $failOnResourceHttpStatusCodes
@@ -1024,6 +1059,7 @@ private function assertChromiumPdfOptions(
10241059 string |null $ waitForExpression ,
10251060 string |null $ waitForSelector ,
10261061 string |null $ emulatedMediaType ,
1062+ array $ emulatedMediaFeatures ,
10271063 array $ cookies ,
10281064 string |null $ userAgent ,
10291065 array $ extraHttpHeaders ,
@@ -1117,6 +1153,15 @@ private function assertChromiumPdfOptions(
11171153 $ this ->assertContainsFormValue ($ body , 'emulatedMediaType ' , $ emulatedMediaType );
11181154 }
11191155
1156+ if (count ($ emulatedMediaFeatures ) > 0 ) {
1157+ $ json = json_encode ($ emulatedMediaFeatures );
1158+ if ($ json === false ) {
1159+ throw NativeFunctionErrored::createFromLastPhpError ();
1160+ }
1161+
1162+ $ this ->assertContainsFormValue ($ body , 'emulatedMediaFeatures ' , $ json );
1163+ }
1164+
11201165 if (count ($ cookies ) > 0 ) {
11211166 $ json = json_encode ($ cookies );
11221167 if ($ json === false ) {
0 commit comments