Sandcastle only postMessage for communication with the viewer#13154
Sandcastle only postMessage for communication with the viewer#13154
postMessage for communication with the viewer#13154Conversation
|
Thank you for the pull request, @jjspace! ✅ We can confirm we have a CLA on file for you. |
@cjj884 Yes, this pr adds |
Sounds good. Please add these details into TM to clarify the iframe isolation in place for viewer. https://github.com/CesiumGS/cesium-analytics/pull/1084#discussion_r2742899254 |
|
One initial reaction is that this may be unclear to devs spinning up locally.
It seems going to http://localhost:8081/ loads the landing page, but sandcastle does not work, is that expected? If we only want devs to go to 8080, perhaps we should suppress the |
I was not expecting people to try and open 8081 directly. I think it's helpful for devs to know something is running on that port so I'm not sure a better way to share that information. People should still just use 8080 as normal
Where are you trying to run that? That command only works when you're in the sandcastle package directory. Are you getting any errors or messages? |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
|
@lukemckinstry please check the console for any lines like this and try to resolve them For example this one needs you to run |
|
@lukemckinstry I pushed a few small changes to relax the dev server and ignore missing files. This may mean it breaks but I think errors in devtools will hopefully point to what files are missing. Certain files like the types should already be handled by the UI gracefully. I also made the local dev server just fully "mirror" and reuse the express |
|
Still getting the same error when I try to run |
|
@jjspace just got back to this, if I run Is that something you want to fix, just document, or neither? |

Description
As part of ongoing discussions and work to add a login system for sandcastle we've been looking at locking the viewer down more. One of the best ways to do that is to separate it out to it's own origin entirely. This would not be possible with the current way we push code into the
iframeto "run" a sandcastle.This PR aims to replace all communication between the Sandcastle app and Viewer "bucket" with
postMessagecalls between the windows. This will enable the viewer/iframe to be anywhere and still work. Locally for now this may still be the same origin/domain for each andpostMessagewill still work.After this change we conceptually have 3 distinct "applications". The Main Sandcastle, the Standalone page and the Viewer bucket which can be hosted independently of the others. We also have a dedicated library in
Sandcastle.tsfor the helpers available in Sandcastle code.The communication between windows now looks something like this:
sequenceDiagram App->>Viewer: page load Viewer->>App: postMessage(bucketReady) App->>Viewer: postMessage(runCode) Viewer->Viewer: Apply code opt Console messages Viewer->>App: postMessage(consoleLog, etc.) end opt Sandcastle helpers Viewer->>App: postMessage(highlight) end App->>Viewer: postMessage(reload) Viewer->Viewer: reload page (return to top)Implementation
IframeBridgeclass which aims to encapsulate the checks for theoriginmessages come from and are sent to as recommended by MDN and other sourcesvite. This could alternatively be determined at runtime but I wasn't sure we wanted to list them all in the source? Open to discussionsandboxattribute withallow-scriptsandallow-same-originto the bucket iframe now that we don't need direct JS access to run the codeSancastle-client.jsfile into more dedicatedConsoleWrapperclass/system and narrowbucket-clientfocused on the page and code loadingappto get the auto-rebuilding of the libraryIssue number and link
Precursor for the work in #13079
Testing plan
npm run build-sandcastlenpm startand make sure sandcastle works. This is actually already split into 2 origins locally with a second dev servernpm run devand make sure that still works too. this is not split origin unless I can figure out a way for the vite dev server to spin up a second server.Author checklist
CONTRIBUTORS.mdCHANGES.mdwith a short summary of my change