|
@@ -142,14 +142,16 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
.then((handle: puppeteer.ElementHandle<HTMLDivElement>) => {
|
|
.then((handle: puppeteer.ElementHandle<HTMLDivElement>) => {
|
|
if (handle === null) throw new puppeteer.errors.TimeoutError();
|
|
if (handle === null) throw new puppeteer.errors.TimeoutError();
|
|
return handle.evaluate(div => {
|
|
return handle.evaluate(div => {
|
|
- const selector = '[data-testid="tweet"]>:nth-child(2)>:first-child a';
|
|
|
|
- const getProfileUrl = () => div.querySelector<HTMLAnchorElement>(selector).href;
|
|
|
|
- const ownerProfileUrl = getProfileUrl();
|
|
|
|
- // eslint-disable-next-line no-cond-assign
|
|
|
|
- while (div = div.previousElementSibling as HTMLDivElement) {
|
|
|
|
- if (getProfileUrl() !== ownerProfileUrl) continue;
|
|
|
|
- return document.documentElement.scrollTop = window.scrollY + div.getBoundingClientRect().top;
|
|
|
|
- }
|
|
|
|
|
|
+ try {
|
|
|
|
+ const selector = '[data-testid="tweet"]>:nth-child(2)>:first-child a';
|
|
|
|
+ const getProfileUrl = () => (div.querySelector<HTMLAnchorElement>(selector) || {href: ''}).href;
|
|
|
|
+ const ownerProfileUrl = getProfileUrl();
|
|
|
|
+ // eslint-disable-next-line no-cond-assign
|
|
|
|
+ while (div = div.previousElementSibling as HTMLDivElement) {
|
|
|
|
+ if (getProfileUrl() !== ownerProfileUrl) continue;
|
|
|
|
+ return document.documentElement.scrollTop = window.scrollY + div.getBoundingClientRect().top;
|
|
|
|
+ }
|
|
|
|
+ } catch {/* handle errors like none-found cases */}
|
|
document.documentElement.scrollTop = 0;
|
|
document.documentElement.scrollTop = 0;
|
|
});
|
|
});
|
|
})
|
|
})
|