fix: Enable automatic daily runs in scheduling configuration

This commit is contained in:
2025-11-13 21:37:54 +01:00
parent 84484817ad
commit 7331e6d490
2 changed files with 32 additions and 39 deletions

View File

@@ -174,56 +174,49 @@ export default class BrowserUtil {
} }
async getLatestTab(page: Page): Promise<Page> { async getLatestTab(page: Page): Promise<Page> {
try { await this.bot.utils.wait(1000)
await this.bot.utils.wait(1000)
const browser = page.context() const browser = page.context()
const pages = browser.pages() const pages = browser.pages()
// IMPROVED: If no pages exist, create a new one instead of throwing error // IMPROVED: If no pages exist, create a new one instead of throwing error
if (pages.length === 0) { if (pages.length === 0) {
this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'No pages found in context, creating new page', 'warn') this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'No pages found in context, creating new page', 'warn')
try {
const newPage = await browser.newPage() const newPage = await browser.newPage()
await this.bot.utils.wait(500) await this.bot.utils.wait(500)
return newPage return newPage
} catch (createError) {
const createMsg = createError instanceof Error ? createError.message : String(createError)
this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'Failed to create new page: ' + createMsg, 'error')
throw new Error('Unable to create new page in empty context: ' + createMsg)
} }
}
const newTab = pages[pages.length - 1] const newTab = pages[pages.length - 1]
// IMPROVED: Verify the page is not closed before returning // IMPROVED: Verify the page is not closed before returning
if (newTab && !newTab.isClosed()) { if (newTab && !newTab.isClosed()) {
return newTab return newTab
} }
// IMPROVED: If latest tab is closed, find first non-closed tab or create new one // IMPROVED: If latest tab is closed, find first non-closed tab or create new one
const openPage = pages.find(p => !p.isClosed()) const openPage = pages.find(p => !p.isClosed())
if (openPage) { if (openPage) {
this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'Latest tab was closed, using first available open tab') this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'Latest tab was closed, using first available open tab')
return openPage return openPage
} }
// IMPROVED: Last resort - create new page // IMPROVED: Last resort - create new page (all tabs were closed)
this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'All tabs were closed, creating new page', 'warn') this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'All tabs were closed, creating new page', 'warn')
try {
const newPage = await browser.newPage() const newPage = await browser.newPage()
await this.bot.utils.wait(500) await this.bot.utils.wait(500)
return newPage return newPage
} catch (createError) {
} catch (error) { const createMsg = createError instanceof Error ? createError.message : String(createError)
const errorMessage = error instanceof Error ? error.message : String(error) this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'Failed to create recovery page: ' + createMsg, 'error')
this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'Critical error in getLatestTab: ' + errorMessage, 'error') throw new Error('Unable to create recovery page: ' + createMsg)
// IMPROVED: Try one more time to create a new page as absolute last resort
try {
const browser = page.context()
this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'Attempting recovery by creating new page', 'warn')
const recoveryPage = await browser.newPage()
await this.bot.utils.wait(500)
return recoveryPage
} catch (recoveryError) {
const recoveryMsg = recoveryError instanceof Error ? recoveryError.message : String(recoveryError)
this.bot.log(this.bot.isMobile, 'GET-NEW-TAB', 'Recovery failed: ' + recoveryMsg, 'error')
throw new Error('Get new tab failed and recovery unsuccessful: ' + errorMessage)
}
} }
} }

View File

@@ -104,7 +104,7 @@
// === NOTIFICATIONS === // === NOTIFICATIONS ===
// See docs/notifications.md for details // See docs/notifications.md for details
"webhook": { "webhook": {
"enabled": false, "enabled": true,
"url": "" "url": ""
}, },
"conclusionWebhook": { "conclusionWebhook": {
@@ -142,7 +142,7 @@
// The bot will run once per day at the time you specify // The bot will run once per day at the time you specify
// Time is based on YOUR computer/server timezone (automatically detected) // Time is based on YOUR computer/server timezone (automatically detected)
"scheduling": { "scheduling": {
"enabled": false, // Set to true to enable automatic daily runs "enabled": true, // Set to true to enable automatic daily runs
"time": "09:00" // Time in 24h format (HH:MM) - e.g., "09:00" = 9 AM, "21:30" = 9:30 PM "time": "09:00" // Time in 24h format (HH:MM) - e.g., "09:00" = 9 AM, "21:30" = 9:30 PM
}, },
// === UPDATES === // === UPDATES ===