Browse Source

fix capturing video loading failure

change detection for deleted tweets
Mike L 2 years ago
parent
commit
899ddc1ff3
3 changed files with 6 additions and 4 deletions
  1. 3 2
      dist/webshot.js
  2. 0 0
      dist/webshot.js.map
  3. 3 2
      src/webshot.ts

+ 3 - 2
dist/webshot.js

@@ -78,6 +78,7 @@ class Webshot extends CallableInstance {
                         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.addStyleTag({
                         content: 'header,#layers{display:none!important}article{background-color:transparent!important}' +
@@ -89,7 +90,7 @@ class Webshot extends CallableInstance {
                         .then(() => page.evaluate(() => {
                         const poll = setInterval(() => {
                             document.querySelectorAll('div[data-testid="placementTracking"]').forEach(container => {
-                                if (container) {
+                                if (container.querySelector('div[role="button"] svg')) {
                                     container.innerHTML = container.innerHTML;
                                     clearInterval(poll);
                                 }
@@ -105,7 +106,7 @@ class Webshot extends CallableInstance {
                         return utils_1.chainPromises(sensitiveToggles.filter(toggle => toggle.isVisible()).map(toggle => () => toggle.click()));
                     })
                         .then(() => handle))
-                        .then(handle => handle.$('xpath=.//a[contains(@href,"notices-on-twitter")]').then(placeholder => placeholder ? null : handle))
+                        .then(handle => handle.$('[data-testid="tweet"]').then(owner => owner ? handle : null))
                         .catch((err) => {
                         if (err.name !== 'TimeoutError')
                             throw err;

File diff suppressed because it is too large
+ 0 - 0
dist/webshot.js.map


+ 3 - 2
src/webshot.ts

@@ -103,6 +103,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
             width: width / zoomFactor,
             height: height / zoomFactor,
           })
+            .then(() => page.route('*:\/\/video.twimg.com\/**', route => { route.abort(); }))
             .then(() => page.goto(url, {waitUntil: 'load', timeout: getTimeout()}))
             // hide header, "more options" button, like and retweet count
             .then(() => page.addStyleTag({
@@ -116,7 +117,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
             .then(() => page.evaluate(() => {
               const poll = setInterval(() => {
                 document.querySelectorAll('div[data-testid="placementTracking"]').forEach(container => {
-                  if (container) {
+                  if (container.querySelector('div[role="button"] svg')) {
                     container.innerHTML = container.innerHTML;
                     clearInterval(poll);
                   }
@@ -135,7 +136,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
               .then(() => handle)
             )
             // throw early if tweet is unavailable
-            .then(handle => handle.$('xpath=.//a[contains(@href,"notices-on-twitter")]').then(placeholder => placeholder ? null : handle))
+            .then(handle => handle.$('[data-testid="tweet"]').then(owner => owner ? handle : null))
             .catch((err: Error): Promise<puppeteer.ElementHandle<HTMLDivElement> | null> => {
               if (err.name !== 'TimeoutError') throw err;
               logger.warn(`navigation timed out at ${getTimerTime()} ms`);

Some files were not shown because too many files changed in this diff