Files
react/packages/react-devtools-extensions/src/background/tabsManager.js
T
Ruslan Lesiutin 795b3207ce fix[react-devtools/extensions]: fixed tabs API calls and displaying restricted access popup (#30825)
Stacked on https://github.com/facebook/react/pull/30824. See [this
commit](https://github.com/facebook/react/pull/30825/commits/c9830d64749cf8fd592ea30a1cd65842cf83f6df).

Turns out we should be listing `tabs` in our permissions, if we want to
be able to receive tab url, once its updated.
This also fixes `chrome.tabs.onCreated` event subscription, because [it
should receive only tab
object](https://developer.chrome.com/docs/extensions/reference/api/tabs#event-onCreated),
and not 3 arguments, as expected in the previous implementation.
2024-08-29 11:31:43 +01:00

32 lines
958 B
JavaScript

/* global chrome */
'use strict';
import setExtensionIconAndPopup from './setExtensionIconAndPopup';
function isRestrictedBrowserPage(url) {
if (!url) {
return true;
}
const urlProtocol = new URL(url).protocol;
return urlProtocol === 'chrome:' || urlProtocol === 'about:';
}
function checkAndHandleRestrictedPageIfSo(tab) {
if (tab && isRestrictedBrowserPage(tab.url)) {
setExtensionIconAndPopup('restricted', tab.id);
}
}
// 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(tab => checkAndHandleRestrictedPageIfSo(tab));
// Listen to URL changes on the active tab and update the DevTools icon.
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.url && isRestrictedBrowserPage(changeInfo.url)) {
setExtensionIconAndPopup('restricted', tabId);
}
});