domeccleston/sharegpt

Error generating avatar image

montyclt opened this issue · 0 comments

When clicking on "Share" button, the console logs "Error generating avatar image." and process never complete*.

Debugging the extension, in index.js L133, this function is defined:

function getAvatarImage() {
  // Create a canvas element
  try {
    const canvas = document.createElement("canvas");

    const image = document.querySelectorAll("img")[3];

    // Set the canvas size to 30x30 pixels
    canvas.width = 48;
    canvas.height = 48;

    // Draw the img onto the canvas
    canvas.getContext("2d").drawImage(image, 0, 0);

    // Convert the canvas to a base64 string as a JPEG image
    const base64 = canvas.toDataURL("image/jpeg");

    return base64;
  } catch (error) {
    console.log("Error generating avatar image.");
    return null;
  }
}

Specifically, the problem is in the line const image = document.querySelectorAll("img")[3];. The NodeList length is 3, so the elements are 0, 1 and 2. The element 3 don't exists and the catch block is called.

*After this error, I got these other error. I think the process never complete is related to the other error, not this.