Skip to content

Fix verification and editor sync against current Chrome and Scratch - #38

Open
jasharpe wants to merge 1 commit into
Waakul:masterfrom
jasharpe:fix/onmessage-async-listener
Open

Fix verification and editor sync against current Chrome and Scratch#38
jasharpe wants to merge 1 commit into
Waakul:masterfrom
jasharpe:fix/onmessage-async-listener

Conversation

@jasharpe

@jasharpe jasharpe commented Aug 23, 2026

Copy link
Copy Markdown

Two regressions from Scratch changes made the extension silently do nothing: verification never completed, and no edit ever reached the server.

Verification (background.js): the getUsername onMessage listener was async, so it returned a Promise for every message, not just the ones it's supposed to handle. This means the slower handlers like auth.js's verify? cannot reply and verification doesn't work. Neither branch awaits before calling sendResponse, so dropping async is safe.

Editor sync (scripts/editor.js): Several Blockly/scratch-blocks APIs no longer exist, and the first failure aborted activateLivescratch() before blockListener was registered.

Fixes:

  • Republish window.Blockly from the trapped ScratchBlocks instance (the page's Blockly global lost getMainWorkspace()), and guard its call sites so they can't throw before the trap fires.
  • Resolve the workspace via getMainWorkspace() and the dragged block via the current gesture, replacing the retired WorkspaceDB_, topBlocks_, and block drag surface (also dropping the now-dead getFlyout).
  • Skip events flagged isUiEvent, whose 'drag' payload port.postMessage() cannot serialize.
  • Anchor the revert button on any menu-bar button now that the "See Project Page" span is gone.

Verified by going into developer mode, loading the unpacked extension, and verifying that verification works and edits are now saved.

Claude was used to make the code changes in this PR. I don't have expertise in this area but wanted to fix the extension because it's currently broken.

Two regressions from the platform moving under the extension made it silently
do nothing: verification never completed, and no edit ever reached the server.

Verification (background.js): the getUsername onMessage listener was `async`,
so it returned a Promise for every message, and Chrome now delivers the
resolved value (undefined) as the response, closing the channel before slower
handlers like auth.js's `verify?` could reply. Neither branch awaits before
calling sendResponse, so dropping `async` is safe.

Editor sync (scripts/editor.js): several Blockly/scratch-blocks APIs no longer
exist, and the first failure aborted activateLivescratch() before blockListener
was registered. Republish window.Blockly from the trapped ScratchBlocks
instance (the page's Blockly global lost getMainWorkspace()), and guard its
call sites so they can't throw before the trap fires. Resolve the workspace
via getMainWorkspace() and the dragged block via the current gesture, replacing
the retired WorkspaceDB_, topBlocks_, and block drag surface (also dropping the
now-dead getFlyout). Skip events flagged isUiEvent, whose 'drag' payload
port.postMessage() cannot serialize. Anchor the revert button on any menu-bar
button now that the "See Project Page" span is gone.

Verified the API and DOM changes against the live scratch.mit.edu editor.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jasharpe
jasharpe force-pushed the fix/onmessage-async-listener branch from cc82fa7 to 72868fe Compare August 24, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant