microsoft / microsoft/pxt-microbit

Deployed MakeCode maintains WebUSB connection with inactive tab, local `pxt serve` doesn't

Open
#4,954 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cli P2
Dominant language
TypeScript
Stars
804
Forks
721
Avg merge
2d 9h
Merged PRs (30d)
2

Description

Testing locally with macOS and the default configuration:

git clone https://github.com/microsoft/pxt-microbit.git
cd pxt-microbit
npm install
npx pxt serve

With a simple programme sends some serial data: https://makecode.microbit.org/_YxU1cDhkjYs3

image

As soon as the micro:bit is WebUSB connected we can see the orange DAPLink LED blinking every second or so, which indicates it's sending the "hello" string. This is as expected, so all good so far.

However, a this point, there is a difference between https://makecode.microbit.org and serving locally:

  • Online Makecode: When the tab is switched or the minimised, the WebUSB connection is still active and we can see the orangle LED still blinking (sending serial data) once per second.
  • Local pxt serve: As soon as the tab is inactive the orange LED stops blinking. When the MakeCode tab is on focus again the micro:bit resets and the orange LED starts blinking again.

So it looks like the online deployment maintain the WebUSB connection when the tab is inactive, and the local serve does not, so it reconnects when the tab comes back on focus.

I noticed this when looking at why the micro:bit was resetting twice on WebUSB connections (raised PR https://github.com/microsoft/pxt-microbit/pull/4953 as part of that).

Is this on purpose? Is there a specific setting to switch this behaviour?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the local npx pxt serve entry point and reproduce the WebUSB behavior using the setup and serial-data program described in the issue. Compare the inactive-tab behavior with deployed MakeCode, then determine whether a setting explains the difference or whether a code change is needed; done means the intended behavior and any required change are established.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
embedded-iot, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.