Files
react/packages/react-devtools-extensions/src/contentScripts/fileFetcher.js
T
Ruslan Lesiutin 24a2ba03fb [DevTools] fix: dedupe file fetch requests and define a timeout (#34566)
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.
2025-09-23 11:38:07 -07:00

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);
}
});