Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am getting a blank screenshot. #27

Open
usamamashkoor opened this issue Mar 2, 2022 · 5 comments
Open

I am getting a blank screenshot. #27

usamamashkoor opened this issue Mar 2, 2022 · 5 comments

Comments

@usamamashkoor
Copy link

Whenever I use this plugin to take a screenshot, I always get a blank screenshot.

I am using the example code, but still, it is not working on my website, This is my code.


import React, { createRef } from "react";
// import Text from "./Text";
import { useScreenshot, createFileName } from "use-react-screenshot";

export default () => {
    const ref = createRef(null);
    const [image, takeScreenShot] = useScreenshot({
        type: "image/jpeg",
        quality: 1.0
    });

    const download = (image, { name = "img", extension = "jpg" } = {}) => {
        const a = document.createElement("a");
        a.href = image;
        a.download = createFileName(extension, name);
        a.click();
    };

    const downloadScreenshot = () => takeScreenShot(ref.current).then(download);

    return (
        <div>
            <button onClick={downloadScreenshot}>Download screenshot</button>
            <div
                ref={ref}
                style={{
                    border: "1px solid #ccc",
                    padding: "10px",
                    marginTop: "20px"
                }}
            >
                Hellow World
            </div>
        </div>
    );
};

@jaspervermeulen
Copy link

Did you check to install the peerDependencie html2canvas? I didn't read the docs and had issues to. :)

@shahan007
Copy link

@usamamashkoor

Were you able to fix it ? I am also getting an invisible image. Downloaded image only has the text in the screenshot but not the image itself, which is missing.

@gubbigubbi
Copy link

This is mostly like due to a CORS issue with html2canvas - refer here

@tawago
Copy link
Contributor

tawago commented Jul 20, 2022

#36

@avoguga
Copy link

avoguga commented Dec 2, 2022

observe if you are using images in another origin.

And try to use: useCORS: true like the others said.
If that doesn't work, try to review the webservice you are using for hosting the image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants