ソースを参照

fix capturing video loading failure

Mike L 3 年 前
コミット
fc334b39fd
2 ファイル変更4 行追加2 行削除
  1. 2 1
      dist/webshot.js
  2. 2 1
      src/webshot.ts

+ 2 - 1
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);
                                 }

+ 2 - 1
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);
                   }