diff --git a/packages/react-devtools-extensions/icons/128-restricted.png b/packages/react-devtools-extensions/icons/128-restricted.png new file mode 100644 index 0000000000000..67b1c9a31a6df Binary files /dev/null and b/packages/react-devtools-extensions/icons/128-restricted.png differ diff --git a/packages/react-devtools-extensions/icons/16-restricted.png b/packages/react-devtools-extensions/icons/16-restricted.png new file mode 100644 index 0000000000000..2f0317ea3fd6b Binary files /dev/null and b/packages/react-devtools-extensions/icons/16-restricted.png differ diff --git a/packages/react-devtools-extensions/icons/32-restricted.png b/packages/react-devtools-extensions/icons/32-restricted.png new file mode 100644 index 0000000000000..7c75045323888 Binary files /dev/null and b/packages/react-devtools-extensions/icons/32-restricted.png differ diff --git a/packages/react-devtools-extensions/icons/48-restricted.png b/packages/react-devtools-extensions/icons/48-restricted.png new file mode 100644 index 0000000000000..372b6e00e88a8 Binary files /dev/null and b/packages/react-devtools-extensions/icons/48-restricted.png differ diff --git a/packages/react-devtools-extensions/icons/restricted.svg b/packages/react-devtools-extensions/icons/restricted.svg new file mode 100644 index 0000000000000..73c2bb51cdbbc --- /dev/null +++ b/packages/react-devtools-extensions/icons/restricted.svg @@ -0,0 +1 @@ +disabled \ No newline at end of file diff --git a/packages/react-devtools-extensions/popups/deadcode.html b/packages/react-devtools-extensions/popups/deadcode.html index 4073f80bde204..5b458981e006b 100644 --- a/packages/react-devtools-extensions/popups/deadcode.html +++ b/packages/react-devtools-extensions/popups/deadcode.html @@ -1,15 +1,11 @@ + +

+ This is a restricted browser page. +
+ React devtools cannot access this page. +

diff --git a/packages/react-devtools-extensions/popups/shared.css b/packages/react-devtools-extensions/popups/shared.css new file mode 100644 index 0000000000000..cd3d35d005897 --- /dev/null +++ b/packages/react-devtools-extensions/popups/shared.css @@ -0,0 +1,7 @@ +html, body { + font-size: 14px; +} + +body { + margin: 8px; +} \ No newline at end of file diff --git a/packages/react-devtools-extensions/src/background.js b/packages/react-devtools-extensions/src/background.js index 1a8302c2b1dfd..cfe5e3c7a9738 100644 --- a/packages/react-devtools-extensions/src/background.js +++ b/packages/react-devtools-extensions/src/background.js @@ -78,17 +78,43 @@ function setIconAndPopup(reactBuildType, tabId) { }); } -// Listen to URL changes on the active tab and reset the DevTools icon. -// This prevents non-disabled icons from sticking in Firefox. -// Don't listen to this event in Chrome though. -// It fires more frequently, often after onMessage() has been called. -if (IS_FIREFOX) { - chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { +function isRestrictedBrowserPage(url) { + return !url || new URL(url).protocol === 'chrome:'; +} + +function checkAndHandleRestrictedPageIfSo(tab) { + if (tab && isRestrictedBrowserPage(tab.url)) { + setIconAndPopup('restricted', tab.id); + } +} + +// update popup page of any existing open tabs, if they are restricted browser pages. +// we can't update for any other types (prod,dev,outdated etc) +// as the content script needs to be injected at document_start itself for those kinds of detection +// TODO: Show a different popup page(to reload current page probably) for old tabs, opened before the extension is installed +if (!IS_FIREFOX) { + chrome.tabs.query({}, tabs => tabs.forEach(checkAndHandleRestrictedPageIfSo)); + chrome.tabs.onCreated.addListener((tabId, changeInfo, tab) => + checkAndHandleRestrictedPageIfSo(tab), + ); +} + +// Listen to URL changes on the active tab and update the DevTools icon. +chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { + if (IS_FIREFOX) { + // We don't properly detect protected URLs in Firefox at the moment. + // However we can reset the DevTools icon to its loading state when the URL changes. + // It will be updated to the correct icon by the onMessage callback below. if (tab.active && changeInfo.status === 'loading') { setIconAndPopup('disabled', tabId); } - }); -} + } else { + // Don't reset the icon to the loading state for Chrome or Edge. + // The onUpdated callback fires more frequently for these browsers, + // often after onMessage has been called. + checkAndHandleRestrictedPageIfSo(tab); + } +}); chrome.runtime.onMessage.addListener((request, sender) => { if (sender.tab) {