# WebSerial library not showing initial prints

**URL:** <https://forum.arduino.cc/t/webserial-library-not-showing-initial-prints/1331292>\
**Category:** Libraries\
**Created:** [December 11, 2024, 2:47pm UTC](https://forum.arduino.cc/t/webserial-library-not-showing-initial-prints/1331292 "2024-12-11T14:47:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hserras](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hserras/32/1127303_2.png) [@hserras](https://forum.arduino.cc/u/hserras)\
**Post date:** [December 11, 2024, 2:47pm UTC](https://forum.arduino.cc/t/webserial-library-not-showing-initial-prints/1331292/1 "2024-12-11T14:47:00Z")

</div>

Hello everyone,

Really sorry if this post wont be well formatted or even written, but it's the first time I open a post here.  
I started using the WebSerial library, currently version 2.0.8, in order to print some stuff there. But the main issue is with the "callbacks". The first callbacks are not being printed in the WebSerial UI.

The code I'm using is the official one, and from what I see, everything is fine, but something is wrong.

The callback code from the official site and it's precisely the same than mine:

**Official code**

> <https://github.com/ayushsharma82/WebSerial/blob/master/examples/Demo/Demo.ino>

```arduino
WebSerial.onMessage([&](uint8_t *data, size_t len) {
    Serial.printf("Received %u bytes from WebSerial: ", len);
    Serial.write(data, len);
    Serial.println();
    WebSerial.println("Received Data...");
    String d = "";
    for(size_t i=0; i < len; i++){
      d += char(data[i]);
    }
    WebSerial.println(d);
  });

```

**My code**

```arduino
WebSerial.onMessage([](uint8_t *data, size_t len) {
  Serial.printf("Received %u bytes from WebSerial: ", len);
  Serial.write(data, len);
  Serial.println();
  WebSerial.println("Received Data...");
  String d = "";
  for(size_t i=0; i < len; i++){
    d += char(data[i]);
  }
  WebSerial.println(d);
});

```

If you see the serial prints that are printed, you see that I clicked 9 times, from 1 to 9:

```arduino
14:37:06.433 -> Received 2 bytes from WebSerial: 1
14:37:07.729 -> Received 2 bytes from WebSerial: 2
14:37:08.309 -> Received 2 bytes from WebSerial: 3
14:37:09.056 -> Received 2 bytes from WebSerial: 4
14:37:10.087 -> Received 2 bytes from WebSerial: 5
14:37:10.680 -> Received 2 bytes from WebSerial: 6
14:37:11.075 -> Received 2 bytes from WebSerial: 7
14:37:11.613 -> Received 2 bytes from WebSerial: 8
14:37:12.097 -> Received 2 bytes from WebSerial: 9

```

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/a/c/0/ac0ff65906e95505564c32835ffae87939cb005d.png)

If I see the webserial, which should have barely the same information, the first two entries somehow seem to remain on some sort of "cache", because they are printed later on

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/f/b/3/fb37aa8eb78a33d0ee1b3555e1f90940d04f95cc.png)

So, the order of this was:  
In Webserial, I clicked 1 and nothing was printed;  
In Webserial, I clicked 2 and nothing was printed;  
In Webserial, I clicked 3 and it printed 1;  
In Webserial, I clicked 4 and it printed 2;

And so on and so on.  
Is there an issue with the library itself?  
Can someone help out on this, since this is a pretty weird behavior?  
I believe my code is fine, since it's precisely the official one

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 9, 2025, 2:47pm UTC](https://forum.arduino.cc/t/webserial-library-not-showing-initial-prints/1331292/2 "2025-06-09T14:47:43Z")

</div>

Closed on June 9, 2025, 2:47pm UTC

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