From c8348dbd7020e34c1b9ecc9356b3e8cb8f8a1398 Mon Sep 17 00:00:00 2001 From: Marcos Passos Date: Fri, 19 Jun 2026 15:17:48 -0400 Subject: [PATCH] Add support for debug mode --- src/Croct.php | 14 +++++++++++++- tests/CroctTest.php | 13 ++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Croct.php b/src/Croct.php index 1f4f5b9..5ec9c41 100644 --- a/src/Croct.php +++ b/src/Croct.php @@ -44,18 +44,22 @@ final class Croct implements Plug private CookieConfiguration $cookieConfiguration; + private bool $debug; + private function __construct( string $appId, Session $session, Evaluator $evaluator, ContentFetcher $contentFetcher, CookieConfiguration $cookieConfiguration, + bool $debug, ) { $this->appId = $appId; $this->session = $session; $this->evaluator = $evaluator; $this->contentFetcher = $contentFetcher; $this->cookieConfiguration = $cookieConfiguration; + $this->debug = $debug; } /** @@ -73,6 +77,7 @@ public static function plug( ?IdentityResolver $identity = null, ?string $baseEndpointUrl = null, int $tokenDuration = self::DEFAULT_TOKEN_DURATION, + bool $debug = false, ?ContentProvider $contentProvider = null, ?RequestContext $context = null, ?HttpClient $httpClient = null, @@ -126,6 +131,7 @@ public static function plug( $contentProvider ?? self::discoverContentProvider(), ), $cookieConfiguration, + $debug, ); } @@ -250,11 +256,17 @@ public function getUserToken(): Token */ public function getPlugOptions(): array { - return [ + $options = [ 'appId' => $this->appId, 'disableCidMirroring' => true, 'cookie' => $this->cookieConfiguration->toBrowserCookies(), ]; + + if ($this->debug) { + $options['debug'] = true; + } + + return $options; } /** diff --git a/tests/CroctTest.php b/tests/CroctTest.php index d82f8c7..b3714c5 100644 --- a/tests/CroctTest.php +++ b/tests/CroctTest.php @@ -198,6 +198,16 @@ public function testExposesPlugOptions(): void ); } + #[TestDox('Forwards the debug flag to the browser plug options when enabled.')] + public function testForwardsDebugToPlugOptions(): void + { + $enabled = $this->createCroct(new MockClient(), debug: true); + $disabled = $this->createCroct(new MockClient()); + + self::assertTrue($enabled->getPlugOptions()['debug'] ?? null); + self::assertArrayNotHasKey('debug', $disabled->getPlugOptions()); + } + #[TestDox('Fetches slot content with the resolved session.')] public function testFetchContentUsesResolvedSession(): void { @@ -380,7 +390,7 @@ public function testEmitsCookiesFromGlobalStorage(): void self::assertSame(self::CLIENT_ID, $emitted['ct_client_id'] ?? null); } - private function createCroct(MockClient $client, ?IdentityStore $storage = null): Plug + private function createCroct(MockClient $client, ?IdentityStore $storage = null, bool $debug = false): Plug { $factory = new Psr17Factory(); $storage ??= new InMemoryIdentityStore(); @@ -389,6 +399,7 @@ private function createCroct(MockClient $client, ?IdentityStore $storage = null) appId: self::APP_ID, apiKey: ApiKey::of(EcKeyFactory::IDENTIFIER), storage: $storage, + debug: $debug, context: new RequestContext(), httpClient: $client, requestFactory: $factory,