From 63bf6c2375eac96f39de110f977e2959a6f095c5 Mon Sep 17 00:00:00 2001 From: Mengdi Chen Date: Tue, 18 Apr 2023 19:55:20 -0400 Subject: [PATCH] (patch)[DevTools] bug fix: backend injection logic not working for undocked devtools window --- packages/react-devtools-extensions/src/background.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react-devtools-extensions/src/background.js b/packages/react-devtools-extensions/src/background.js index 89d87724dda..8861b63f589 100644 --- a/packages/react-devtools-extensions/src/background.js +++ b/packages/react-devtools-extensions/src/background.js @@ -172,6 +172,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { chrome.runtime.onMessage.addListener((request, sender) => { const tab = sender.tab; + // sender.tab.id from content script points to the tab that injected the content script if (tab) { const id = tab.id; // This is sent from the hook content script. @@ -214,7 +215,10 @@ chrome.runtime.onMessage.addListener((request, sender) => { break; } } - } else if (request.payload?.tabId) { + } + // sender.tab.id from devtools page may not exist, or point to the undocked devtools window + // so we use the payload to get the tab id + if (request.payload?.tabId) { const tabId = request.payload?.tabId; // This is sent from the devtools page when it is ready for injecting the backend if (request.payload.type === 'react-devtools-inject-backend-manager') {