@@ -16,6 +16,7 @@ func takeScreenshot(ofURL url: String, outputPath: String, delay: Int? = nil, ca
1616 " --output= \" \( outputPath) \" " ,
1717 " --overwrite " ,
1818 " --full-page " ,
19+ " --timeout=30 " , // decrease timeout to prevent waiting for elements that are not there anymore
1920 " --user-agent= \" Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36 \" "
2021 ]
2122 if let delay = delay, delay > 0 {
@@ -162,11 +163,14 @@ func handleScreenshotError(entry: URLEntry) throws {
162163 }
163164
164165 // If an error file already exists, get the attributes and check the creation date
166+ print ( " Error file already exists " )
165167 if fileManager. fileExists ( atPath: errorFile) ,
166- let creationDate = try fileManager. attributesOfItem ( atPath: errorFile) [ . creationDate] as? Date ,
167- creationDate. distance ( to: Date ( ) ) >= kErrorReportDuration {
168- // Notify the user that an error persisted for the last `errorReportTime` seconds
169- try notifyError ( entry: entry)
168+ let creationDate = try fileManager. attributesOfItem ( atPath: errorFile) [ . creationDate] as? Date {
169+ print ( " Creation date: \( creationDate) ( \( creationDate. distance ( to: Date ( ) ) / 3600 ) hours ago " )
170+ if creationDate. distance ( to: Date ( ) ) >= kErrorReportDuration {
171+ // Notify the user that an error persisted for the last `errorReportTime` seconds
172+ try notifyError ( entry: entry)
173+ }
170174 }
171175}
172176
@@ -179,7 +183,8 @@ func notifyError(entry: URLEntry) throws {
179183 // TODO: Replace with DateComponentsFormatter when available on Linux
180184 let f = SharedUtils . DummyFormatter ( fullUnits: true )
181185 let durationString = f. string ( from: kErrorReportDuration) ?? " some time "
182- try sendTelegramMessage ( " The entry ' \( entry. name) ' failed to capture a screenshot for at least \( durationString) . " ,
186+ try sendTelegramMessage ( " The entry ' \( entry. name) ' failed to capture a screenshot for at least " +
187+ " \( durationString. isEmpty ? " some time " : durationString) . " ,
183188 to: Int ( entry. chatID) )
184189}
185190
0 commit comments