processing/processing-website

storeItem value must be serializable, not "any type"

Closed this issue · 0 comments

The documentation of getItem() currently says:

The second parameter, value, is the value to be stored. Values can have any type.

However value can only accept JSON serializable values. Trying to store for example an image results in an error:

p5.min.js:2 Uncaught 
TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'r'
    --- property '_pixelsState' closes the circle
    at JSON.stringify (<anonymous>)
    at n.default.storeItem (p5.min.js:2:554483)
    at <anonymous>:1:1

An example of a workaround to store an image could be added as an example, using toDataURL():

yourImage.canvas.toDataURL()