waiting for the tab to load properly
This commit is contained in:
parent
3e96681d03
commit
580410c4b3
1 changed files with 19 additions and 0 deletions
|
|
@ -210,6 +210,25 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
|||
createdWindowID = newWindow.id;
|
||||
let createdTab = newWindow.tabs[0];
|
||||
|
||||
// Wait for tab loaded.
|
||||
await new Promise(resolve => {
|
||||
const tabIsLoaded = tab => {
|
||||
return tab.status == "complete" && tab.url != "about:blank";
|
||||
};
|
||||
const listener = (tabId, changeInfo, updatedTab) => {
|
||||
if (tabIsLoaded(updatedTab)) {
|
||||
browser.tabs.onUpdated.removeListener(listener);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
// Early exit if loaded already
|
||||
if (tabIsLoaded(createdTab)) {
|
||||
resolve();
|
||||
} else {
|
||||
browser.tabs.onUpdated.addListener(listener);
|
||||
}
|
||||
});
|
||||
|
||||
let mailMessage = await browser.messageDisplay.getDisplayedMessage(curr_tabId);
|
||||
let mailMessageId = -1;
|
||||
if(mailMessage) mailMessageId = mailMessage.id;
|
||||
|
|
|
|||
Loading…
Reference in a new issue