@@ -189,8 +189,8 @@ export class Driver implements Debuggable, UpdateSource {
189189 }
190190 } ) ;
191191
192- // Handle the fetch, message, and push, notificationclick,
193- // notificationclose and pushsubscriptionchange events.
192+ // Handle the fetch, message, push, notificationclick,
193+ // notificationclose, pushsubscriptionchange, and messageerror events.
194194 this . scope . addEventListener ( 'fetch' , ( event ) => this . onFetch ( event ! ) ) ;
195195 this . scope . addEventListener ( 'message' , ( event ) => this . onMessage ( event ! ) ) ;
196196 this . scope . addEventListener ( 'push' , ( event ) => this . onPush ( event ! ) ) ;
@@ -201,6 +201,7 @@ export class Driver implements Debuggable, UpdateSource {
201201 // based on the incorrect assumption that browsers don't support it.
202202 this . onPushSubscriptionChange ( event as PushSubscriptionChangeEvent ) ,
203203 ) ;
204+ this . scope . addEventListener ( 'messageerror' , ( event ) => this . onMessageError ( event ) ) ;
204205
205206 // The debugger generates debug pages in response to debugging requests.
206207 this . debugger = new DebugHandler ( this , this . adapter ) ;
@@ -338,6 +339,15 @@ export class Driver implements Debuggable, UpdateSource {
338339 event . waitUntil ( this . handlePushSubscriptionChange ( event ) ) ;
339340 }
340341
342+ private onMessageError ( event : MessageEvent ) : void {
343+ // Handle message deserialization errors that occur when receiving messages
344+ // that cannot be deserialized, typically due to corrupted data or unsupported formats.
345+ this . debugger . log (
346+ `Message error occurred - data could not be deserialized` ,
347+ `Driver.onMessageError(origin: ${ event . origin } )` ,
348+ ) ;
349+ }
350+
341351 private async ensureInitialized ( event : ExtendableEvent ) : Promise < void > {
342352 // Since the SW may have just been started, it may or may not have been initialized already.
343353 // `this.initialized` will be `null` if initialization has not yet been attempted, or will be a
0 commit comments