Browse Source

fix: wrong image output when taking full page screenshot enabled

Ahmad Kholid 3 years ago
parent
commit
ae402a9ea2
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/content/blocks-handler/handler-take-screenshot.js

+ 6 - 2
src/content/blocks-handler/handler-take-screenshot.js

@@ -56,7 +56,9 @@ export default async function ({ tabId, options }) {
   const context = canvas.getContext('2d');
   const maxCanvasSize = 32767;
 
-  const scrollableElement = findScrollableElement();
+  const scrollElement = document.querySelector('.automa-scrollable-el');
+  let scrollableElement = scrollElement || findScrollableElement();
+
   const takeScreenshot = async () => {
     await sendMessage('set:active-tab', tabId, 'background');
     const imageUrl = await sendMessage(
@@ -74,7 +76,7 @@ export default async function ({ tabId, options }) {
     return imageUrl;
   }
 
-  scrollableElement.classList.add('automa-scrollable-el');
+  scrollableElement.classList?.add('automa-scrollable-el');
 
   const style = injectStyle();
   const originalYPosition = window.scrollY;
@@ -97,6 +99,8 @@ export default async function ({ tabId, options }) {
 
   let scrollPosition = 0;
 
+  if (scrollableElement.tagName === 'HTML') scrollableElement = window;
+
   while (scrollPosition <= originalScrollHeight) {
     const imageUrl = await takeScreenshot();