Skip to content

Commit d680c99

Browse files
kblokclaude
andcommitted
fix: restore VerifyInterception exception and align error handling with upstream
Remove the erroneous early-return guard (if !PageLevelInterceptionEnabled return) that was silently swallowing calls to ContinueAsync/RespondAsync/AbortAsync when interception was not enabled. The correct behavior, matching upstream Puppeteer, is for VerifyInterception() to throw "Request Interception is not enabled!" so that ShouldThrowIfInterceptionIsNotEnabled passes on Firefox BiDi. Also align ContinueInternalAsync and RespondInternalAsync error handling with upstream's handleError: re-throw header-validation errors (Invalid header, Unsafe header, Expected "header", invalid argument) and silently swallow all other WebDriverBiDiException protocol errors (cancelled request, etc.). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 564e4ce commit d680c99

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

lib/PuppeteerSharp/Bidi/BidiHttpRequest.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ public override InterceptResolutionState InterceptResolutionState
124124
/// <inheritdoc />
125125
public override async Task ContinueAsync(Payload payloadOverrides = null, int? priority = null)
126126
{
127-
if (!PageLevelInterceptionEnabled)
128-
{
129-
return;
130-
}
131-
132127
VerifyInterception();
133128

134129
if (!CanBeIntercepted())
@@ -172,11 +167,6 @@ public override async Task RespondAsync(ResponseData response, int? priority = n
172167
throw new ArgumentNullException(nameof(response));
173168
}
174169

175-
if (!PageLevelInterceptionEnabled)
176-
{
177-
return;
178-
}
179-
180170
VerifyInterception();
181171

182172
if (!CanBeIntercepted())
@@ -214,11 +204,6 @@ public override async Task RespondAsync(ResponseData response, int? priority = n
214204
/// <inheritdoc />
215205
public override async Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed, int? priority = null)
216206
{
217-
if (!PageLevelInterceptionEnabled)
218-
{
219-
return;
220-
}
221-
222207
VerifyInterception();
223208

224209
if (!CanBeIntercepted())
@@ -480,10 +465,18 @@ await _request.ContinueRequestAsync(
480465

481466
// Only swallow specific protocol errors that are safe to ignore.
482467
// Match upstream's handleError behavior.
483-
if (ex is WebDriverBiDi.WebDriverBiDiException bidiEx &&
484-
(bidiEx.Message.Contains("Invalid request id") ||
485-
bidiEx.Message.Contains("no such request")))
468+
if (ex is WebDriverBiDi.WebDriverBiDiException bidiEx)
486469
{
470+
// Re-throw header validation errors — the user should see those.
471+
// Swallow all other protocol errors (request already cancelled, etc.).
472+
if (bidiEx.Message.Contains("Invalid header") ||
473+
bidiEx.Message.Contains("Unsafe header") ||
474+
bidiEx.Message.Contains("Expected \"header\"") ||
475+
bidiEx.Message.Contains("invalid argument"))
476+
{
477+
throw;
478+
}
479+
487480
return;
488481
}
489482

@@ -503,7 +496,6 @@ private async Task AbortInternalAsync()
503496
{
504497
IsInterceptResolutionHandled = false;
505498

506-
// Only swallow specific protocol errors that are safe to ignore.
507499
if (ex is WebDriverBiDi.WebDriverBiDiException bidiEx &&
508500
(bidiEx.Message.Contains("Invalid request id") ||
509501
bidiEx.Message.Contains("no such request")))
@@ -587,11 +579,18 @@ await _request.ProvideResponseAsync(
587579
{
588580
IsInterceptResolutionHandled = false;
589581

590-
// Only swallow specific protocol errors that are safe to ignore.
591-
if (ex is WebDriverBiDi.WebDriverBiDiException bidiEx &&
592-
(bidiEx.Message.Contains("Invalid request id") ||
593-
bidiEx.Message.Contains("no such request")))
582+
if (ex is WebDriverBiDi.WebDriverBiDiException bidiEx)
594583
{
584+
// Re-throw header validation errors — the user should see those.
585+
// Swallow all other protocol errors (request already cancelled, etc.).
586+
if (bidiEx.Message.Contains("Invalid header") ||
587+
bidiEx.Message.Contains("Unsafe header") ||
588+
bidiEx.Message.Contains("Expected \"header\"") ||
589+
bidiEx.Message.Contains("invalid argument"))
590+
{
591+
throw;
592+
}
593+
595594
return;
596595
}
597596

0 commit comments

Comments
 (0)