MCPcopy Index your code
hub / github.com/darkreader/darkreader / sendMessage

Function sendMessage

src/api/chrome.ts:16–34  ·  view source on GitHub ↗
(...args: any[])

Source from the content-addressed store, hash-verified

14const messageListeners = new Set<(message: MessageBGtoCS) => void>();
15
16async function sendMessage(...args: any[]) {
17 if (args[0] && args[0].type === MessageTypeCStoBG.FETCH) {
18 const {id} = args[0];
19 try {
20 const {url, responseType} = args[0].data;
21 const response = await callFetchMethod(url);
22 let text: string;
23 if (responseType === 'data-url') {
24 text = await readResponseAsDataURL(response);
25 } else {
26 text = await response.text();
27 }
28 messageListeners.forEach((cb) => cb({type: MessageTypeBGtoCS.FETCH_RESPONSE, data: text, error: null, id}));
29 } catch (error) {
30 console.error(error);
31 messageListeners.forEach((cb) => cb({type: MessageTypeBGtoCS.FETCH_RESPONSE, data: null, error, id}));
32 }
33 }
34}
35
36function addMessageListener(callback: (data: any) => void) {
37 messageListeners.add(callback);

Callers 1

chrome.tsFile · 0.70

Calls 2

callFetchMethodFunction · 0.90
readResponseAsDataURLFunction · 0.90

Tested by

no test coverage detected