1515 */
1616
1717import type { Json } from '@metamask/utils' ;
18- import { stringify } from '@ocap/utils' ;
18+ import { makeLogger , stringify } from '@ocap/utils' ;
19+ import type { Logger } from '@ocap/utils' ;
1920
2021import type { ChromeRuntime , ChromeMessageSender } from './chrome.d.ts' ;
2122import {
@@ -67,6 +68,8 @@ export class ChromeRuntimeReader<Read extends Json> extends BaseReader<Read> {
6768
6869 readonly #extensionId: string ;
6970
71+ readonly #logger: Logger ;
72+
7073 constructor (
7174 runtime : ChromeRuntime ,
7275 target : ChromeRuntimeTarget ,
@@ -91,6 +94,7 @@ export class ChromeRuntimeReader<Read extends Json> extends BaseReader<Read> {
9194 this . #target = target ;
9295 this . #source = source ;
9396 this . #extensionId = runtime . id ;
97+ this . #logger = makeLogger ( `[chrome-runtime-reader ${ this . #extensionId} ]` ) ;
9498
9599 messageListener = this . #onMessage. bind ( this ) ;
96100 // Begin listening for messages from the Chrome runtime.
@@ -105,19 +109,15 @@ export class ChromeRuntimeReader<Read extends Json> extends BaseReader<Read> {
105109 }
106110
107111 if ( ! isMessageEnvelope ( message ) ) {
108- console . debug (
109- `ChromeRuntimeReader received unexpected message: ${ stringify (
110- message ,
111- ) } `,
112- ) ;
112+ this . #logger. debug ( `received unexpected message: ${ stringify ( message ) } ` ) ;
113113 return ;
114114 }
115115
116116 if ( message . target !== this . #target || message . source !== this . #source) {
117- console . debug (
118- `ChromeRuntimeReader received message with incorrect target or source: ${ stringify ( message ) } ` ,
119- `Expected target: ${ this . #target} ` ,
120- `Expected source: ${ this . #source} ` ,
117+ this . #logger . debug (
118+ `received message with incorrect target or source: ${ stringify ( message ) } ` ,
119+ `expected target: ${ this . #target} ` ,
120+ `expected source: ${ this . #source} ` ,
121121 ) ;
122122 return ;
123123 }
0 commit comments