mdbassit / Coloris

A lightweight and elegant JavaScript color picker. Written in vanilla ES6, no dependencies. Accessible.
https://coloris.js.org/examples.html
MIT License
451 stars 58 forks source link

Unchecked runtime.lastError: This request exceeds the MAX_WRITE_OPERATIONS_PER_MINUTE quota. #89

Closed CommanderRaiker closed 1 year ago

CommanderRaiker commented 1 year ago

Hi,

I implement your code with the parameter onChange so I can save a selected color after selection. Unfortunately the event fires multiple times when clicking an holding the mouse button to move around the color palette to choose a color. Is it possible, that the onChange Even only fires onmouseup?

Otherwise I think this color picker is very nice. You done a very nice job.

mdbassit commented 1 year ago

I assume you are using this as part of a Chrome extension. You will need to use a throttling technique to avoid that error. I will not be changing the behavior of onChange. Here is an example of throttling using setTimeout:

// This will store a timer id 
let timeOut;

// Configure Coloris (or a Coloris instance)
Coloris({
  el: '.coloris',
  onChange: color => {
    // Abort if setTimeout has already been called
    if (timeOut) {
      return;
    }

    // Schedule an action after 1 second delay
    timeOut = setTimeout(() => {
      // Call your custom function after the delay
      mySaveFunction();

      // Set the timer id to undefined to mark the scheduled action as finished
      timeOut  =  undefined;
    }, 1000);
  }
});