GithubHelp home page GithubHelp logo

fayeed / use-screenshot Goto Github PK

View Code? Open in Web Editor NEW
51.0 1.0 11.0 364 KB

React hook to take screenshot for React components.

Home Page: https://use-screenshot.now.sh/

HTML 3.45% TypeScript 46.04% CSS 45.09% JavaScript 5.42%
react reactjs hooks screenshot html-to-image html2canvas

use-screenshot's Issues

Not working on Safari?

I was unable to get this to work on Safari; however it did work on Chrome for Mac. Is that a known issue?

TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
at px (index.es.js?2c84:170:1)
at Object.getNodeWidth (index.es.js?2c84:174:1)
at getImageSize (index.es.js?2c84:800:1)
at toSvgDataURL (index.es.js?2c84:806:1)
at toCanvas (index.es.js?2c84:816:1)
at toPng (index.es.js?2c84:847:1)
at eval (index.es.js?2c84:897:1)
at step (index.es.js?2c84:50:1)
at Object.eval [as next] (index.es.js?2c84:31:46)
at eval (index.es.js?2c84:24:1)
at new Promise ()
at __awaiter (index.es.js?2c84:20:1)
at eval (index.es.js?2c84:882:65)
at onClick (Third.tsx?bc39:427:32)
at HTMLUnknownElement.callCallback (react-dom.development.js?61bb:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js?61bb:3994:1)
at invokeGuardedCallback (react-dom.development.js?61bb:4056:1)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js?61bb:4070:1)
at executeDispatch (react-dom.development.js?61bb:8243:1)
at processDispatchQueueItemsInOrder (react-dom.development.js?61bb:8275:1)
at processDispatchQueue (react-dom.development.js?61bb:8288:1)
at dispatchEventsForPlugins (react-dom.development.js?61bb:8299:1)
at eval (react-dom.development.js?61bb:8508:1)
at batchedEventUpdates$1 (react-dom.development.js?61bb:22396:1)
at batchedEventUpdates (react-dom.development.js?61bb:3745:1)
at dispatchEventForPluginEventSystem (react-dom.development.js?61bb:8507:1)
at attemptToDispatchEvent (react-dom.development.js?61bb:6005:1)
at dispatchEvent (react-dom.development.js?61bb:5924:1)
at unstable_runWithPriority (scheduler.development.js?3069:468:1)
at runWithPriority$1 (react-dom.development.js?61bb:11276:1)
at discreteUpdates$1 (react-dom.development.js?61bb:22413:1)
at discreteUpdates (react-dom.development.js?61bb:3756:1)
at dispatchDiscreteEvent (react-dom.development.js?61bb:5889:1)

Screenshot for scrollable div

I have a scrollable div, that I pass ref in to it, but it only takes the screenshot from the top part of the div, and I want it to take the screenshot of the full height.
Is this possible?

I am getting a blank screenshot.

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>
    );
};

Is it possible to take screen shot in which one dive has live streaming?

I have a project requirement in which there are two divs who will start live streaming i.e. video calls when they connected over the network.

So Is it can achieve with this library? There are header and sidebar components as well. So along with it, I want a screenshot of the whole page which contains the header, sidebar, and the live streaming as well.

Please help me out!

TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

const ref = createRef()
const { image, takeScreenshot } = useScreenshot({ ref: ref })

return(
  <div ref={ref as React.RefObject<HTMLDivElement>}>
    {selectedItem && (
      <>
        <img
          className={`
                  ${css({
                    objectFit: 'cover',
                    objectPosition: 'center',
                    maxWidth: '100%',
                  })}
                  h-100
                `}
          src={getImage(selectedItem.images['3x']) || ''}
          alt={'img'}
        />
        <button onClick={() => takeScreenshot()}>TouchMe</button>
      </>
    )}
  </div>
)

It is returning the error TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

I think this error is because I am using nextJS.

Getting document.getElementById('root') is getting null, we should get document.getElementById('__next'), then, we can improve the library sending a new param with the id we want to get like as "root" in the useScreenShot() function or if it is returning null check with the first "root", try with "__next".

Masked image in not rendering in a screenshot using css properties

well, I am trying to take a screenshot of a particular div/component that contains a layered/masked image using usescreenshot in react, though I am only getting the color of the topmost layer that i am dynamically changing using color picker, what i actually want is to change the color of a car's body, tyre and rim using color picker and then take a screenshot of my color choice but i am unable to find a direction how to resolve?
const generateImgRef = useRef(null);
<button onClick={() => exportAsImage(generateImgRef.current, "test")}>

colors
test (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.