1212
1313use PlaywrightPHP \Configuration \PlaywrightConfig ;
1414use PlaywrightPHP \Event \EventDispatcherInterface ;
15+ use PlaywrightPHP \Exception \ProtocolErrorException ;
16+ use PlaywrightPHP \Exception \TransportException ;
1517use PlaywrightPHP \Network \NetworkThrottling ;
1618use PlaywrightPHP \Network \Route ;
1719use PlaywrightPHP \Page \Page ;
@@ -60,10 +62,10 @@ public function dispatchEvent(string $eventName, array $params): void
6062 {
6163 if ('route ' === $ eventName ) {
6264 if (!is_string ($ params ['routeId ' ])) {
63- throw new \ RuntimeException ('Invalid routeId in route event ' );
65+ throw new ProtocolErrorException ('Invalid routeId in route event ' , 0 );
6466 }
6567 if (!is_array ($ params ['request ' ])) {
66- throw new \ RuntimeException ('Invalid request data in route event ' );
68+ throw new ProtocolErrorException ('Invalid request data in route event ' , 0 );
6769 }
6870 $ route = new Route (
6971 $ this ->transport ,
@@ -126,11 +128,11 @@ public function newPage(array $options = []): PageInterface
126128
127129 if (isset ($ response ['error ' ])) {
128130 $ errorMsg = is_string ($ response ['error ' ]) ? $ response ['error ' ] : 'Unknown transport error ' ;
129- throw new \ RuntimeException ('Transport error in newPage: ' .$ errorMsg );
131+ throw new TransportException ('Transport error in newPage: ' .$ errorMsg );
130132 }
131133
132134 if (!isset ($ response ['pageId ' ]) || !is_string ($ response ['pageId ' ])) {
133- throw new \ RuntimeException ('No valid pageId returned from transport in newPage ' );
135+ throw new ProtocolErrorException ('No valid pageId returned from transport in newPage ' , 0 );
134136 }
135137
136138 $ page = new Page ($ this ->transport , $ this , $ response ['pageId ' ], $ this ->config );
@@ -147,7 +149,7 @@ public function clipboardText(): string
147149 ]);
148150
149151 if (!is_string ($ response ['value ' ])) {
150- throw new \ RuntimeException ('Invalid clipboard text response ' );
152+ throw new ProtocolErrorException ('Invalid clipboard text response ' , 0 );
151153 }
152154
153155 return $ response ['value ' ];
@@ -210,7 +212,7 @@ public function cookies(?array $urls = null): array
210212 ]);
211213
212214 if (!is_array ($ response ['cookies ' ])) {
213- throw new \ RuntimeException ('Invalid cookies response ' );
215+ throw new ProtocolErrorException ('Invalid cookies response ' , 0 );
214216 }
215217
216218 /** @phpstan-var array<array<string, mixed>> $cookies */
@@ -271,7 +273,7 @@ public function storageState(?string $path = null): array
271273 ]);
272274
273275 if (!is_array ($ response ['storageState ' ])) {
274- throw new \ RuntimeException ('Invalid storageState response ' );
276+ throw new ProtocolErrorException ('Invalid storageState response ' , 0 );
275277 }
276278
277279 /** @phpstan-var array<string, mixed> $storageState */
@@ -420,13 +422,13 @@ public function disableNetworkThrottling(): void
420422 private function validateTransportArray (mixed $ data , string $ context = '' ): array
421423 {
422424 if (!is_array ($ data )) {
423- throw new \ RuntimeException ("Invalid {$ context } data in transport response " );
425+ throw new ProtocolErrorException ("Invalid {$ context } data in transport response " , 0 );
424426 }
425427
426428 $ result = [];
427429 foreach ($ data as $ key => $ value ) {
428430 if (!is_string ($ key )) {
429- throw new \ RuntimeException ("Invalid {$ context } payload: non-string key in transport response " );
431+ throw new ProtocolErrorException ("Invalid {$ context } payload: non-string key in transport response " , 0 );
430432 }
431433 $ result [$ key ] = $ value ;
432434 }
0 commit comments