mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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.
32 lines
958 B
JavaScript
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);
|
|
}
|
|
});
|