# Javascript bug: getImageData() returns incorrect values

**URL:** <https://community.brave.app/t/javascript-bug-getimagedata-returns-incorrect-values/208592>\
**Category:** Uncategorized\
**Tags:** bug\
**Created:** [February 20, 2021, 1:42pm UTC](https://community.brave.app/t/javascript-bug-getimagedata-returns-incorrect-values/208592 "2021-02-20T13:42:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alikim](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@alikim](https://community.brave.app/u/alikim)\
**Post date:** [February 20, 2021, 1:42pm UTC](https://community.brave.app/t/javascript-bug-getimagedata-returns-incorrect-values/208592/1 "2021-02-20T13:42:59Z")

</div>

here my JS code:

```
  function test2D() {
  const c = document.getElementById("aux");
  const ctx = c.getContext("2d");

  ctx.beginPath();
  ctx.rect(0, 0, 10, 10);
  ctx.fillStyle = "#102030";
  ctx.fill();

  ctx.beginPath();
  ctx.rect(0, 0, 5, 3);
  ctx.fillStyle = "#100000";
  ctx.fill();
  
  const data = ctx.getImageData(0, 0, 10, 10).data;
  let str = '';
  data.forEach((b,i)=> {str+=parseInt(b)+', '; if((i+1) % 4 == 0) str += '\n';});
  console.log(str);
}

test2D();

```

> **[brave bug - JSFiddle - Code Playground](https://jsfiddle.net/tfoller/6armw15b/1/)**
>
> Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.

and here is what I see in your Browser (1.20.103 Win10):

```
16, 0, 0, 255, 
16, 1, 0, 255, 
16, 1, 0, 255, 
16, 0, 0, 255, 
16, 1, 0, 255, 
16, 32, 48, 255, 
16, 33, 48, 255, 
16, 33, 48, 255, 
16, 32, 48, 255, 
16, 33, 48, 255, 
16, 0, 0, 255, 
16, 0, 0, 255, 
16, 1, 0, 255,
...

```

random 33 instead of 32 in

> 16, 33, 48, 255,

and 1 instead of 0 in

> 16, 1, 0, 255,

This code works perfectly in FF 85 and Chrome 88 (desktop Win10) but not in Brave.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/brave/original/3X/1/8/182067f3480d1a5e7aea5ae3131b116ca1ef7918.png) [@system](https://community.brave.app/u/system)\
**Post date:** [April 21, 2021, 1:43pm UTC](https://community.brave.app/t/javascript-bug-getimagedata-returns-incorrect-values/208592/2 "2021-04-21T13:43:41Z")

</div>

Closed on April 21, 2021, 1:43pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
