Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[react-devtools/extensions]: fixed tabs API calls and displaying restricted access popup #30825

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/react-devtools-extensions/chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
},
"permissions": [
"storage",
"scripting"
"scripting",
"tabs"
],
"host_permissions": [
"<all_urls>"
Expand Down
3 changes: 2 additions & 1 deletion packages/react-devtools-extensions/edge/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
},
"permissions": [
"storage",
"scripting"
"scripting",
"tabs"
],
"host_permissions": [
"<all_urls>"
Expand Down
3 changes: 2 additions & 1 deletion packages/react-devtools-extensions/firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
]
},
"permissions": [
"scripting"
"scripting",
"tabs"
],
"host_permissions": [
"<all_urls>"
Expand Down
20 changes: 11 additions & 9 deletions packages/react-devtools-extensions/src/background/tabsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import setExtensionIconAndPopup from './setExtensionIconAndPopup';

function isRestrictedBrowserPage(url) {
return !url || new URL(url).protocol === 'chrome:';
if (!url) {
return true;
}

const urlProtocol = new URL(url).protocol;
return urlProtocol === 'chrome:' || urlProtocol === 'about:';
}

function checkAndHandleRestrictedPageIfSo(tab) {
Expand All @@ -14,16 +19,13 @@ function checkAndHandleRestrictedPageIfSo(tab) {
}
}

// 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
// Update popup page of any existing open tabs, if they are restricted browser pages
chrome.tabs.query({}, tabs => tabs.forEach(checkAndHandleRestrictedPageIfSo));
chrome.tabs.onCreated.addListener((tabId, changeInfo, tab) =>
checkAndHandleRestrictedPageIfSo(tab),
);
chrome.tabs.onCreated.addListener(tab => checkAndHandleRestrictedPageIfSo(tab));

// Listen to URL changes on the active tab and update the DevTools icon.
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
checkAndHandleRestrictedPageIfSo(tab);
if (changeInfo.url && isRestrictedBrowserPage(changeInfo.url)) {
setExtensionIconAndPopup('restricted', tabId);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ import {registerDevToolsEventLogger} from 'react-devtools-shared/src/registerDev

function registerEventsLogger() {
registerDevToolsEventLogger('extension', async () => {
// TODO: after we upgrade to Firefox Manifest V3, chrome.tabs.query returns a Promise without the callback.
return new Promise(resolve => {
chrome.tabs.query({active: true}, tabs => {
resolve({
page_url: tabs[0]?.url,
});
});
});
const tabs = await chrome.tabs.query({active: true});
return {page_url: tabs[0]?.url};
});
}

Expand Down
Loading