File tree Expand file tree Collapse file tree 3 files changed +26
-4
lines changed
react-devtools-extensions/src
react-devtools-shared/src Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -115,7 +115,17 @@ function createPanelIfReactLoaded() {
115115
116116 const tabId = chrome . devtools . inspectedWindow . tabId ;
117117
118- registerDevToolsEventLogger ( 'extension' ) ;
118+ registerDevToolsEventLogger ( 'extension' , async ( ) => {
119+ // TODO: after we upgrade to Manifest V3, chrome.tabs.query returns a Promise
120+ // without the callback.
121+ return new Promise ( resolve => {
122+ chrome . tabs . query ( { active : true , currentWindow : true } , tabs => {
123+ resolve ( {
124+ page_url : tabs [ 0 ] ?. url ,
125+ } ) ;
126+ } ) ;
127+ } ) ;
128+ } ) ;
119129
120130 function initBridgeAndStore ( ) {
121131 const port = chrome . runtime . connect ( {
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ export type LogEvent =
3333 + inspected_element_number_of_hooks : number | null ,
3434 | } ;
3535
36- export type LogFunction = LogEvent => void ;
36+ export type LogFunction = LogEvent => void | Promise < void > ;
3737
3838let logFunctions : Array < LogFunction > = [ ] ;
3939export const logEvent : LogFunction =
Original file line number Diff line number Diff line change @@ -15,8 +15,17 @@ import {enableLogger} from 'react-devtools-feature-flags';
1515let loggingIFrame = null ;
1616let missedEvents = [ ] ;
1717
18- export function registerDevToolsEventLogger ( surface : string ) {
19- function logEvent ( event : LogEvent ) {
18+ type LoggerContext = { |
19+ page_url : ?string ,
20+ | } ;
21+
22+ export function registerDevToolsEventLogger (
23+ surface : string ,
24+ fetchAdditionalContext : ?( ) = >
25+ | LoggerContext
26+ | ?( ( ) => Promise < LoggerContext > ) ,
27+ ) : void {
28+ async function logEvent ( event : LogEvent ) {
2029 if ( enableLogger ) {
2130 if ( loggingIFrame != null ) {
2231 loggingIFrame . contentWindow . postMessage (
@@ -26,6 +35,9 @@ export function registerDevToolsEventLogger(surface: string) {
2635 context : {
2736 surface,
2837 version : process . env . DEVTOOLS_VERSION ,
38+ ...( fetchAdditionalContext != null
39+ ? await fetchAdditionalContext ( )
40+ : { } ) ,
2941 } ,
3042 } ,
3143 '*' ,
You can’t perform that action at this time.
0 commit comments