main
js 48 lines 1.04 KB
Raw
1 /* global chrome */
2
3 function fetchResource(url) {
4 const reject = value => {
5 chrome.runtime.sendMessage({
6 source: 'react-devtools-fetch-resource-content-script',
7 payload: {
8 type: 'fetch-file-with-cache-error',
9 url,
10 value,
11 },
12 });
13 };
14
15 const resolve = value => {
16 chrome.runtime.sendMessage({
17 source: 'react-devtools-fetch-resource-content-script',
18 payload: {
19 type: 'fetch-file-with-cache-complete',
20 url,
21 value,
22 },
23 });
24 };
25
26 fetch(url, {cache: 'force-cache', signal: AbortSignal.timeout(60000)}).then(
27 response => {
28 if (response.ok) {
29 response
30 .text()
31 .then(text => resolve(text))
32 .catch(error => reject(null));
33 } else {
34 reject(null);
35 }
36 },
37 error => reject(null),
38 );
39 }
40
41 chrome.runtime.onMessage.addListener(message => {
42 if (
43 message?.source === 'devtools-page' &&
44 message?.payload?.type === 'fetch-file-with-cache'
45 ) {
46 fetchResource(message.payload.url);
47 }
48 });