11window . runCompare = async function ( ) {
22
3- const id = window . location . pathname . split ( '/' ) . pop ( ) ;
3+ const id = getLocalTraceId ( ) ;
44 const base = document . getElementById ( 'baseUrl' ) . value . trim ( ) ;
55 const remoteId = document . getElementById ( 'compareId' ) . value . trim ( ) ;
66
@@ -10,6 +10,7 @@ window.runCompare = async function () {
1010 }
1111
1212 setCompareResult ( '<div class="compare-message">Comparing...</div>' ) ;
13+ setOpenCompareButtonVisible ( false ) ;
1314
1415 try {
1516 const res = await fetch ( `/debug/compare/${ id } ?baseUrl=${ encodeURIComponent ( base ) } &remoteTraceId=${ encodeURIComponent ( remoteId ) } ` ) ;
@@ -21,15 +22,62 @@ window.runCompare = async function () {
2122 }
2223
2324 setCompareResult ( renderCompare ( await res . json ( ) ) ) ;
25+ setOpenCompareButtonVisible ( true ) ;
2426 } catch ( error ) {
2527 setCompareResult ( `<div class="compare-message compare-message-error">${ escapeHtml ( error . message || 'Compare failed' ) } </div>` ) ;
2628 }
2729} ;
2830
31+ window . openCompareInNewTab = function ( ) {
32+ const localTraceId = getLocalTraceId ( ) ;
33+ const base = document . getElementById ( 'baseUrl' ) . value . trim ( ) ;
34+ const traceId = document . getElementById ( 'compareId' ) . value . trim ( ) ;
35+
36+ if ( ! base || ! traceId ) {
37+ return ;
38+ }
39+
40+ const url = `/compare?baseUrl=${ encodeURIComponent ( base ) } &traceId=${ encodeURIComponent ( traceId ) } &localTraceId=${ encodeURIComponent ( localTraceId ) } ` ;
41+ window . open ( url , '_blank' , 'noopener' ) ;
42+ } ;
43+
44+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
45+ const baseInput = document . getElementById ( 'baseUrl' ) ;
46+ const traceInput = document . getElementById ( 'compareId' ) ;
47+
48+ if ( ! baseInput || ! traceInput ) {
49+ return ;
50+ }
51+
52+ const params = new URLSearchParams ( window . location . search ) ;
53+ const baseUrl = params . get ( 'baseUrl' ) ;
54+ const traceId = params . get ( 'traceId' ) ;
55+
56+ if ( ! baseUrl || ! traceId ) {
57+ return ;
58+ }
59+
60+ baseInput . value = baseUrl ;
61+ traceInput . value = traceId ;
62+ window . runCompare ( ) ;
63+ } ) ;
64+
2965function setCompareResult ( html ) {
3066 document . getElementById ( 'compareResult' ) . innerHTML = html ;
3167}
3268
69+ function getLocalTraceId ( ) {
70+ const input = document . getElementById ( 'localTraceId' ) ;
71+ return input ?. value || window . location . pathname . split ( '/' ) . pop ( ) ;
72+ }
73+
74+ function setOpenCompareButtonVisible ( visible ) {
75+ const button = document . getElementById ( 'openCompareTab' ) ;
76+ if ( button ) {
77+ button . hidden = ! visible ;
78+ }
79+ }
80+
3381function renderCompare ( result ) {
3482 const model = buildCompareModel ( result ) ;
3583
0 commit comments