|
@@ -95,25 +95,28 @@ 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;
|
|
|
- });
|
|
|
+ const gotoUrlAndWaitForTweet = () =>
|
|
|
+ page.goto(url, {waitUntil: 'load', timeout: Math.min(10000, getTimeout())})
|
|
|
+ .then(() => Promise.race([
|
|
|
+ page.waitForSelector('article', {state: 'attached', timeout: getTimeout()}),
|
|
|
+ page.click('#placeholder+#ScriptLoadFailure input[value="Try again"]', {timeout: getTimeout()}),
|
|
|
+ page.waitForSelector(
|
|
|
+ 'div[role="button"]>div>span>:text-matches("^やりなおす|更新$")'
|
|
|
+ , {state: 'attached', timeout: getTimeout()}).then(() => page.reload({timeout: getTimeout()})),
|
|
|
+ ]))
|
|
|
+ .catch(err => {
|
|
|
+ if (err.name === 'TimeoutError' && webshotDelay > getTimerTime()) {
|
|
|
+ logger.warn(`navigation timed out after ${getTimerTime()} ms, retrying...`);
|
|
|
+ return gotoUrlAndWaitForTweet();
|
|
|
+ }
|
|
|
+ throw err;
|
|
|
+ });
|
|
|
page.setViewportSize({
|
|
|
width: width / zoomFactor,
|
|
|
height: height / zoomFactor,
|
|
|
})
|
|
|
.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()}),
|
|
|
- page.waitForSelector('div[role="button"]>div>span>:text-matches("^やりなおす|更新$")', {state: 'attached', timeout: getTimeout()})
|
|
|
- .then(() => page.reload({timeout: getTimeout()})),
|
|
|
- ]))
|
|
|
+ .then(gotoUrlAndWaitForTweet)
|
|
|
// hide header, "more options" button, like and retweet count
|
|
|
.then(() => page.addStyleTag({
|
|
|
content: 'header,#layers{display:none!important}article{background-color:transparent!important}' +
|