Coder Social home page Coder Social logo

jhildenbiddle / canvas-size Goto Github PK

View Code? Open in Web Editor NEW
237.0 4.0 18.0 909 KB

Determine the maximum area, height, width, and custom dimensions of an HTML canvas element.

Home Page: https://jhildenbiddle.github.io/canvas-size/

License: MIT License

JavaScript 100.00%
area canvas height html limit maximum offscreen scale size test

canvas-size's People

Contributors

jhildenbiddle avatar sashsvamir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

canvas-size's Issues

Crashing on Android Browsers

  1. Thank you for this library - it's 100% needed.
  2. My apologies in advance if this log is annoying - just figured you'd wanna know. Read through as much as I possibly could in the readme, plus related issues...

This is consistently crashing the Chrome Browser for me on Android Browserstack Pixel 4/5. This was first reported by users in production, so I know it's not just a VM limitation that was outlined in your very helpful readme.

For reference - using it as recommended in the readme as well..

const canvasLimitation = await canvasSize.maxArea({
      usePromise: true,
      useWorker: false,
    });

to reproduce if you'd like you can actually just fire up one of those devices in browserstack and go to your test url.

https://jsbin.com/megedep/1/edit?js,output

I've had it log the failure in the console and crash the browser.

Happy to help debug if you'd like.

Webworker not working [chrome 84.0.4147.125/linux]

image

canvasSize.maxArea({
  useWorker: true,
  onError(width, height, benchmark) {
    console.log('Error', width, height, benchmark);
  },
  onSuccess(width, height, benchmark) {
    console.log('Success', width, height, benchmark);
  }
});

Using the webworker option as documented ends up throwing the error specified above.

Tests fail on latest macOS / Safari

This is a question, assuming it's my lack of understanding and not a bug, really not sure.

I have a completed t-shirt designer application that relies on drawing a large canvas in memory to render a design created by the user. When I encountered issues on mobile devices, I turned to this repo as a solution to warn the user that the tool is unavailable on their device. Thanks!

Unexpectedly, my fix to disable my site on mobile using the canvas test also broke Safari for desktop Macs. The result of calling test({ width: 4189, height: 4790.8 }) is false, but when I query for the maxArea(), the result I get on success has width and height 8192. Why would the test be failing even though the dimensions are within the bounds?

To unblock my progress I am switching to a solution that checks the result of maxArea() but I am concerned that this might not reflect what will happen when I try to render the design.

Chrome allows undetected 65535x1

Not sure about other combinations, but it seems that Chrome allows canvas of size 65535x1 nowadays.

This can be currently detected by manually passing this dimension to the canvasSize.test method, but isn't detected by canvasSize.maxWidth (it still returns 32767x1).

Memory leak

This library does not clean out the memory it's using. Before Chrome uses 116mb, after calling

canvasSize.maxArea({
        onError: (width, height) => {
            console.warn('canvas.maxArea Error:', width, height);
        },
        onSuccess: (width, height) => {
            console.log('canvas.maxArea - width: ' + width.toLocaleString() +
                'px, height: ' + height.toLocaleString() + 'px');
        }
    });

Chrome now uses 1.1GB and does not release that additional 1GB (!).

Performing multiple measurement on Safari for iOS will exceed memory limit

Running the following code on Safari for iOS (15+) will cause the browser to report errors:

  try {
    const test1 = await canvasSize.maxWidth({ usePromise: true })
    console.log('MaxWidth:', test1.width)
    const test2 = await canvasSize.maxHeight({ usePromise: true })
    console.log('MaxHeight:', test2.height)
    const test3 = await canvasSize.maxArea({ usePromise: true })
    console.log('MaxArea:', test3.width, test3.height)
  } catch (err) {
    console.error('Failed to measure canvas size:', err)
  }

Screen Shot 2022-10-19 at 12 57 03 PM

After some research, it seems like we have to "release" the canvas element created for testing immediately after the test is finished, to prevent the browser from holding the memory allocated for the canvas' storage. This affects not only all following canvas tests, but also real canvas applications that load afterwards, as long as they share the same memory usage constraint.

FYI: https://pqina.nl/blog/total-canvas-memory-use-exceeds-the-maximum-limit

Test process questions

Hi, I have a few questions about how the testing process works

  1. It is noted that "Some browsers become unresponsive during tests" during the process. Is there a general sense of which browsers suffer about how much delay?
  2. In the test, we copy a pixel from one canvas to another, then read the second canvas. I guess just reading a pixel from the first pixel would not be accurate enough of a test for some reason?

Webpack optimize CanvasTest error

Hi, first thanks for your work.

I just tried it, and if I specify in webpack.config.js :

module.exports = {
    optimization: {
        minimize: true,
        minimizer: [new TerserPlugin(),
    },
...

This error is thrown :

Uncaught ReferenceError: canvasTest is not defined
    at onmessage (d6ce07e3-5a07-454b-9558-b3c8698cbe7a:4)

I just test this code :

canvasSize.maxArea({
    usePromise: true,
    useWorker : true,
})
    .then(({ width, height, benchmark }) => {
        console.log(`Success: ${width} x ${height} (${benchmark} ms)`);
    })
    .catch(({ width, height, benchmark }) => {
        console.log(`Error: ${width} x ${height} (${benchmark} ms)`);
    });

Did I miss something ?

Best regards

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.