MCPcopy Index your code
hub / github.com/QLHazyCoder/FlowPilot / sendToContentScriptResilient

Function sendToContentScriptResilient

background/tab-runtime.js:549–579  ·  view source on GitHub ↗
(source, message, options = {})

Source from the content-addressed store, hash-verified

547 }
548
549 async function sendToContentScriptResilient(source, message, options = {}) {
550 const { timeoutMs = 30000, retryDelayMs = 600, logMessage = '' } = options;
551 const start = Date.now();
552 let lastError = null;
553 let logged = false;
554 let attempt = 0;
555
556 while (Date.now() - start < timeoutMs) {
557 throwIfStopped();
558 attempt += 1;
559
560 try {
561 return await sendToContentScript(source, message);
562 } catch (err) {
563 const retryable = isRetryableContentScriptTransportError(err);
564 if (!retryable) {
565 throw err;
566 }
567
568 lastError = err;
569 if (logMessage && !logged) {
570 await addLog(logMessage, 'warn');
571 logged = true;
572 }
573
574 await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
575 }
576 }
577
578 throw lastError || new Error(`等待 ${getSourceLabel(source)} 重新就绪超时。`);
579 }
580
581 async function sendToMailContentScriptResilient(mail, message, options = {}) {
582 const { timeoutMs = 45000, maxRecoveryAttempts = 2 } = options;

Callers 7

requestCpaOAuthUrlFunction · 0.70
executeStep6Function · 0.50
executeStep2Function · 0.50
executeStep4Function · 0.50
executeCpaStep9Function · 0.50

Calls 5

sendToContentScriptFunction · 0.70
addLogFunction · 0.70
getSourceLabelFunction · 0.70
throwIfStoppedFunction · 0.50

Tested by

no test coverage detected