Skip to content

Conversation

@doonfrs
Copy link

@doonfrs doonfrs commented Sep 4, 2025

Summary

  • Fixed null safety issue in NavigatedWithinDocumentEvent.fromJson that was causing runtime errors
  • Added proper null handling for url and navigationType fields when they're null in the JSON response

Problem

On some browsers (possibly an old Chrome version), the application was throwing an error: Type 'Null' is not a subtype of type 'String' in type cast when receiving navigation events with null values for the url or navigationType fields.

Solution

Added null-safe casting (as String?) with fallback to empty string (?? '') for both fields to handle null values gracefully.

Test plan

  • Verify that navigation events are handled without throwing exceptions
  • Test that the fix works with both null and non-null values for url and navigationType

Error Stack Trace:

type 'Null' is not a subtype of type 'String' in type cast
  #0      new NavigatedWithinDocumentEvent.fromJson (package:puppeteer/protocol/page.dart:1353:32)
  #1      PageApi.onNavigatedWithinDocument.<anonymous closure> (package:puppeteer/protocol/page.dart:167:52)
  #2      _MapStream._handleData (dart:async/stream_pipe.dart:247:31)
  #3      _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:184:13)
  #4      _RootZone.runUnaryGuarded (dart:async/zone.dart:1778:10)
  #5      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
  #6      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
  #7      _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:154:11)
  #8      _WhereStream._handleData (dart:async/stream_pipe.dart:229:12)
  #9      _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:184:13)
  #10     _RootZone.runUnaryGuarded (dart:async/zone.dart:1778:10)
  #11     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)

doonfrs and others added 2 commits September 4, 2025 03:58
Add null safety handling for url and navigationType fields in
NavigatedWithinDocumentEvent.fromJson to prevent runtime errors
when these fields are null in the JSON response.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Use 'other' instead of empty string as fallback for navigationType
to prevent "No element" error when the enum value is null.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant