|
@@ -95,12 +95,19 @@ class Webshot extends CallableInstance<[Tweet[], (...args) => void, number], Pro
|
|
|
const startTime = new Date().getTime();
|
|
|
const getTimerTime = () => new Date().getTime() - startTime;
|
|
|
const getTimeout = () => Math.max(500, webshotDelay - getTimerTime());
|
|
|
+ const goto = () => page.goto(url, {waitUntil: 'load', timeout: Math.min(10000, getTimeout())}).catch(err => {
|
|
|
+ if (err.name === 'TimeoutError' && webshotDelay > getTimerTime()) {
|
|
|
+ logger.warn(`navigation timed out after ${getTimerTime()} ms, retrying...`);
|
|
|
+ return goto();
|
|
|
+ }
|
|
|
+ throw err;
|
|
|
+ });
|
|
|
page.setViewportSize({
|
|
|
width: width / zoomFactor,
|
|
|
height: height / zoomFactor,
|
|
|
})
|
|
|
- .then(() => page.route('*:\/\/video.twimg.com\/**', route => { route.abort(); }))
|
|
|
- .then(() => page.goto(url, {waitUntil: 'load', timeout: getTimeout()}))
|
|
|
+ .then(() => page.route('*:\/\/video.twimg.com\/**', route => route.abort()))
|
|
|
+ .then(goto)
|
|
|
.then(() => Promise.race([
|
|
|
page.waitForSelector('article', {state: 'attached', timeout: getTimeout()}),
|
|
|
page.click('#placeholder+#ScriptLoadFailure input[value="Try again"]', {timeout: getTimeout()}),
|