Skip to content

Network access in the browser #85

Closed
2 of 2 issues completed
Closed
2 of 2 issues completed
@adamziel

Description

@adamziel

Latest status

Curl and tcp over fetch() are now a part of WordPress Playground 🎉 Here's what we still need to close this issue:


Description

WordPress Playground only has a partial support for network calls.

Types of network calls in WordPress

wp_safe_remote_get

As of #724, Playground is capable of translating wp_safe_remote_get calls into JavaScript fetch() requests. This has limitations:

  • Only https:// URLs are supported
  • The server must provide valid CORS headers in the response
  • Developers can't control all the headers

Arbitrary network calls

Other methods of accessing the network, such as libcurl or file_get_contents, are not supported yet.

Web browsers do not allow the WebAssembly code to access the internet directly yet. A native socket API may or may not be released in the future, but there isn't one for now. #1093 would improve the situation.

In Node.js, Playground access the network using the following method:

  1. Set up a same-domain API endpoint that accepts network commands from the browser
  2. Capture socket function calls in the WebAssembly binary
  3. Pass them to JavaScript
  4. Pass the requested operation over the API endpoint using the fetch() or WebSocket

This may not be viable on the web as someone would have to pay for the hardware to run the proxy on, and the proxy's nature mean there are security risks related to accessing the local network.

Solution

After 1,5 years of exploring and discussing, this issue finally has a path forward:

For full networking support, we'd also need the following:

  • Expose the Node networking proxy as a separate, runnable script
  • Provide an API to connect it to the in-browser version Playground
  • Document the workflow

Nice to haves:

  • Ship a version of the network built in PHP script to enable running a full-featured Playground build in the same environments as WordPress.
  • Provide a Dockerfile to set up the network proxy and a few buttons for quickly spinning proxy cloud nodes on, e.g. CloudFlare, Digital Ocean, etc.

Limitations of the approach

Limitations without the network proxy:

  • Non-CORS URLs wouldn't work
  • Non-HTTPS traffic wouldn't work
  • gethostname and other low-level methods still wouldn't work
  • SSL certificate checks, like the ones done by Composer, wouldn't work

All of the above could be resolved by plugging in a network proxy.

Other Alternatives

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions