fixed the error reporting string. added a max tries to the chatgpt web interface connect script

This commit is contained in:
mic 2024-09-03 21:38:50 +02:00
parent da0fb82794
commit 142907feff

View file

@ -182,8 +182,13 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
`; `;
let done1 = false; let done1 = false;
let try_num = 0;
while(!done1){ while(!done1){
if(try_num > 30){
taLog.error('[ChatGPT Web] Impossible to connect to the window chat!');
break;
}
try { try {
await browser.tabs.executeScript(createdTab.id, { code: pre_script + mzta_script, matchAboutBlank: false }); await browser.tabs.executeScript(createdTab.id, { code: pre_script + mzta_script, matchAboutBlank: false });
let mailMessage = await browser.messageDisplay.getDisplayedMessage(curr_tabId); let mailMessage = await browser.messageDisplay.getDisplayedMessage(curr_tabId);
@ -194,9 +199,10 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
taLog.log("[ThunderAI] ChatGPT Web script injected successfully"); taLog.log("[ThunderAI] ChatGPT Web script injected successfully");
done1 = true; done1 = true;
} catch (error) { } catch (error) {
taLog.warn('[ChatGPT Web] Error connecting to the window chat: ', error); taLog.warn('[ChatGPT Web] Error connecting to the window chat: ' + error);
taLog.warn('[ChatGPT Web] Trying again...'); taLog.warn('[ChatGPT Web] Trying again...');
done1 = false; done1 = false;
try_num++;
} }
await new Promise(resolve => setTimeout(resolve, 500)); await new Promise(resolve => setTimeout(resolve, 500));
} }