Skip to content

Create in-browser Live Development infrastructure based on postMessage #27

@humphd

Description

@humphd

Brackets recently started to evolve its LiveDevelopment feature to work in multiple browsers. The new architecture allows the editor to talk to a browser over a transport layer (currently WebSocket based) and communicate bi-directionally between the preview and editor document(s).

Our goal with Mozilla's editor for Thimble is to leverage this new architecture in order to create an in-browser editor with an in-browser livedev preview which substitute an iframe-based browser, a postMessage-based transport layer, and a nohost-based Blob URL Object server.

Accomplishing this will involve a bunch of things. I've started to make a list below, and I'm CC'ing @busykai for additional thoughts. This list is incomplete, but should get us started.

  • LiveDev needs to default to multi browser (i.e., the livedev.multibrowser pref should be true):

https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/main.js#L77-L80

We can probably use PreferencesManager.set() in an extension to flip this to true at startup. We just need to make sure it happens early enough (i.e., before AppInit.appReady) so as to not miss the multibrowser init here:

https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/main.js#L303-L314

  • Launch/open a browser to display the preview need to be altered:

https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/LiveDevMultiBrowser.js#L517-L527

https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/MultiBrowserImpl/launchers/Launcher.js#L47

We need to change that to not use Node, but to start the iframe-based browser. Maybe we should override the launcher, or maybe we should implement the various “open browser” bits of the appshell:

https://github.com/humphd/brackets/blob/bramble/src/thirdparty/browser-appshell.js#L74-L79

  • We need to create a LiveDevServer that implements enough of the LiveDevelopment/Servers/BaseServer base class. The FileServer is an example:

https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/Servers/FileServer.js

We can do this in an extension. We then need to register this server with the LiveDevServerManager such that it has a high enough priority to always get used (e.g., 9001, which is higher than 0 or 99):

https://github.com/adobe/brackets/blob/14370aedfb6fdb7416a53cb0b7dc8d1a7bd7a5d4/src/LiveDevelopment/LiveDevelopment.js#L1482-L1484

  • We should be able to alter how URLs are created to our server, and instead create Blob URL Objects (i.e., override the pathToUrl method):

https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/Servers/BaseServer.js#L92-L112

One issue to ponder is that we'll need to do this async (i.e., read path from fs), and pathToUrl is sync. The URL gets used with the launcher here:

https://github.com/adobe/brackets/blob/14370aedfb6fdb7416a53cb0b7dc8d1a7bd7a5d4/src/LiveDevelopment/LiveDevMultiBrowser.js#L537-L541

We can steal code from nohost to create the Blob URLs:

https://github.com/humphd/nohost/blob/master/src/handlers.js#L510-L530

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions