Face Sensing loads its MediaPipe files from a root-relative path, and its CDN fallback doesn't run
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript, webpack
- Domain
- build-system, frontend
Research direction
Start with the detector setup in packages/scratch-vm/src/extensions/scratch3_face_sensing/index.js (around lines 94-110, where solutionPath is hard-coded), then compare with the publicPath comment in packages/scratch-gui/webpack.config.js (around lines 131-135). Check that the path resolves under a subdirectory and from file://, using the gui dev server. Done means the models load from the bundle location, and the fallback either goes or a load failure reaches the loading alert. The fallback choice is a maintainer decision, so confirm it before changing it.
Written by the indexing model from the issue text.
Description
Face Sensing creates its detector with a hard-coded, root-relative path:
solutionPath: '/chunks/mediapipe/face_detection' always resolves against the root of the site. The scratch-gui build copies those files next to its other chunks, and the library build uses publicPath: 'auto' so that chunks load relative to the bundle. The comment there says this is for hosts like scratch-desktop and scratch-android:
Face Sensing doesn't follow that rule, so it may fail to load its models when the editor is:
- hosted in a subdirectory (for example
https://example.org/scratch/, where it requestshttps://example.org/chunks/...) - loaded from
file://, where the path points at the root of the filesystem
scratch-android works around this by serving its web app at the root of its origin. Other hosts may not be able to.
The fallback to jsDelivr doesn't help in these cases. In testing on Android, the local load failed but createDetector didn't reject, so the .catch never ran and the "loading extension" alert stayed up. It looks like the files are only requested after createDetector resolves.
Possible fix
- Build the path from webpack's runtime public path, for example
__webpack_public_path__ + 'chunks/mediapipe/face_detection', so it resolves the same way as the gui's other chunks. This should be checked both in the prebuilt guidistand for consumers that build scratch-vm from source through thewebpackexport condition. - Decide whether to keep the CDN fallback at all. If a host forgets to ship the model files, the fallback would hide that while online, and the problem would only show up offline or on networks that block the CDN. It also makes requests to a third party that the host app didn't choose. Failing visibly (for example, an error in the loading alert) may be easier to debug. If the fallback stays, the failure needs to be detected after
createDetectorresolves, or the fallback needs a timeout.
Testing
- the gui dev server
- the editor hosted in a subdirectory
- scratch-desktop
- scratch-android (it should keep working after the fix, with or without its root mapping)
- Dominant language
- JavaScript
- Stars
- 310
- Forks
- 299
- Avg merge
- 19h 41m
- Merged PRs (30d)
- 14
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from scratchfoundation/scratch-editor
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
scratchfoundation/scratch-editor#754 ·
Maintainers usually reply within 1 day
-
spork
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
scratchfoundation/scratch-editor#646 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
scratchfoundation/scratch-editor#406 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 76/100
scratchfoundation/scratch-editor#750 · 1 comment ·
Maintainers usually reply within 1 day
-
Monitor context menus shrink the EditorPossibly taken @mxmou claimed this 3 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 50/100
scratchfoundation/scratch-editor#744 · 6 comments · 1 reaction ·
Maintainers usually reply within 1 day
All issues in scratchfoundation/scratch-editor
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 96/100
google/site-kit-wp#14102 ·
Maintainers usually reply within 2 days
-
area:growth priority:P1 type:docs
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
tecnologiasantos/bogoboom#66 ·
Maintainers usually reply within 1 day
-
desktop docs good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
npm/write-file-atomic#245 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
ktwu01/benchmark-radar#1181 ·
Maintainers usually reply within 1 day