mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
If there is a large owner stack, we could potentially spam multiple fetch requests for the same source map. This adds a simple deduplication logic, based on URL. Also, this adds a timeout of 60 seconds to all fetch requests initiated by fileFetcher content script.
49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
/* global chrome */
|
|
|
|
function fetchResource(url) {
|
|
const reject = value => {
|
|
chrome.runtime.sendMessage({
|
|
source: 'react-devtools-fetch-resource-content-script',
|
|
payload: {
|
|
type: 'fetch-file-with-cache-error',
|
|
url,
|
|
value,
|
|
},
|
|
});
|
|
};
|
|
|
|
const resolve = value => {
|
|
chrome.runtime.sendMessage({
|
|
source: 'react-devtools-fetch-resource-content-script',
|
|
payload: {
|
|
type: 'fetch-file-with-cache-complete',
|
|
url,
|
|
value,
|
|
},
|
|
});
|
|
};
|
|
|
|
fetch(url, {cache: 'force-cache', signal: AbortSignal.timeout(60000)}).then(
|
|
response => {
|
|
if (response.ok) {
|
|
response
|
|
.text()
|
|
.then(text => resolve(text))
|
|
.catch(error => reject(null));
|
|
} else {
|
|
reject(null);
|
|
}
|
|
},
|
|
error => reject(null),
|
|
);
|
|
}
|
|
|
|
chrome.runtime.onMessage.addListener(message => {
|
|
if (
|
|
message?.source === 'devtools-page' &&
|
|
message?.payload?.type === 'fetch-file-with-cache'
|
|
) {
|
|
fetchResource(message.payload.url);
|
|
}
|
|
});
|