@@ -39,6 +39,37 @@ function sanitizeText(value, limit = 240) {
3939 return String ( value || '' ) . trim ( ) . replace ( / \s + / g, ' ' ) . slice ( 0 , limit ) ;
4040}
4141
42+ function sanitizeUrlForDiagnostics ( input ) {
43+ try {
44+ const parsed = new URL ( String ( input || '' ) ) ;
45+ const parts = parsed . pathname . split ( '/' ) . filter ( Boolean ) ;
46+ const first = parts [ 0 ] || '' ;
47+ const second = parts [ 1 ] || '' ;
48+
49+ // Keep only route pattern, remove concrete identifiers/query/hash.
50+ if ( first === 'c' ) return `${ parsed . origin } /c/:id` ;
51+ if ( first === 'g' ) return `${ parsed . origin } /g/:id` ;
52+ if ( ! first ) return `${ parsed . origin } /` ;
53+ if ( second ) return `${ parsed . origin } /${ first } /${ second } ` ;
54+ return `${ parsed . origin } /${ first } ` ;
55+ } catch ( _ ) {
56+ return sanitizeText ( input || '' , 120 ) ;
57+ }
58+ }
59+
60+ function sanitizePageLabel ( inputUrl , platform = '' ) {
61+ const base = sanitizeText ( platform || 'unknown' , 24 ) || 'unknown' ;
62+ try {
63+ const path = new URL ( String ( inputUrl || '' ) ) . pathname || '/' ;
64+ if ( path . includes ( '/c/' ) ) return `${ base } :conversation` ;
65+ if ( path . startsWith ( '/g/' ) ) return `${ base } :project` ;
66+ if ( path . startsWith ( '/apps' ) ) return `${ base } :apps` ;
67+ return `${ base } :page` ;
68+ } catch ( _ ) {
69+ return `${ base } :page` ;
70+ }
71+ }
72+
4273function pruneReportedDiagnostics ( now = Date . now ( ) ) {
4374 const ttl = Number ( getReportingConfig ( ) . dedupeWindowMs ) || ( 30 * 60 * 1000 ) ;
4475 for ( const [ key , ts ] of reportedDiagnostics . entries ( ) ) {
@@ -81,7 +112,7 @@ function sanitizeTurn(turn) {
81112 turnIndex : Number . isFinite ( turn ?. turnIndex ) ? turn . turnIndex : null ,
82113 branchIndex : Number . isFinite ( turn ?. branchIndex ) ? turn . branchIndex : null ,
83114 role : sanitizeText ( turn ?. role , 24 ) ,
84- text : sanitizeText ( turn ?. text || turn ?. textSig , 120 ) ,
115+ text : '' ,
85116 } ;
86117}
87118
@@ -94,14 +125,14 @@ function sanitizeDiagnostics(diagnostics) {
94125 platformLabel : sanitizeText ( diagnostics . platformLabel , 40 ) ,
95126 extensionVersion : sanitizeText ( diagnostics . extensionVersion , 24 ) ,
96127 selectorVersion : sanitizeText ( diagnostics . selectorVersion , 40 ) ,
97- url : sanitizeText ( diagnostics . url , 240 ) ,
128+ url : sanitizeUrlForDiagnostics ( diagnostics . url ) ,
98129 ts : Number . isFinite ( diagnostics . ts ) ? diagnostics . ts : Date . now ( ) ,
99130 turnCount : Number . isFinite ( diagnostics . turnCount ) ? diagnostics . turnCount : 0 ,
100131 probe : {
101132 platform : sanitizeText ( diagnostics . probe ?. platform , 24 ) ,
102133 version : sanitizeText ( diagnostics . probe ?. version , 40 ) ,
103134 ts : Number . isFinite ( diagnostics . probe ?. ts ) ? diagnostics . probe . ts : null ,
104- url : sanitizeText ( diagnostics . probe ?. url , 240 ) ,
135+ url : sanitizeUrlForDiagnostics ( diagnostics . probe ?. url ) ,
105136 hits : diagnostics . probe ?. hits && typeof diagnostics . probe . hits === 'object' ? diagnostics . probe . hits : { } ,
106137 broken : ( Array . isArray ( diagnostics . probe ?. broken ) ? diagnostics . probe . broken : [ ] ) . map ( item => sanitizeText ( item , 60 ) ) ,
107138 } ,
@@ -115,7 +146,7 @@ function sanitizeDiagnostics(diagnostics) {
115146 tag : sanitizeText ( sample ?. tag , 24 ) ,
116147 testid : sanitizeText ( sample ?. testid , 80 ) ,
117148 cls : sanitizeText ( sample ?. cls , 160 ) ,
118- text : sanitizeText ( sample ?. text , 160 ) ,
149+ text : '' ,
119150 } ) ) ,
120151 } ) ) ,
121152 } ;
@@ -169,8 +200,8 @@ async function postReport({ type, diagnostics, description = '', sender }) {
169200 client : 'chrome-extension' ,
170201 publicKey : config . publicKey || '' ,
171202 description : sanitizeText ( description , 1500 ) ,
172- tabUrl : sanitizeText ( sender ?. tab ?. url || sanitized . url , 240 ) ,
173- pageTitle : sanitizeText ( sender ?. tab ?. title || '' , 120 ) ,
203+ tabUrl : sanitizeUrlForDiagnostics ( sender ?. tab ?. url || sanitized . url ) ,
204+ pageTitle : sanitizePageLabel ( sender ?. tab ?. url || sanitized . url , sanitized . platform ) ,
174205 extensionVersion : sanitizeText ( sanitized . extensionVersion , 24 ) ,
175206 selectorVersion : sanitizeText ( sanitized . selectorVersion , 40 ) ,
176207 diagnostics : sanitized ,
0 commit comments