microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.64k stars 3.57k forks source link

[Feature]: `launchServer` to support `exposeNetwork` #31718

Open parrotmac opened 1 month ago

parrotmac commented 1 month ago

Page(s)

Description

Issue

I'm attempting to use a server launched with launchServer() with a client configured with exposeNetwork, but I'm getting net::ERR_CONNECTION_REFUSED with this configuration. Relevant snippets:

Server (running in a Docker container OR a different machine)

const browserServer = await playwright.chromium.launchServer({
    headless: true,
    host: '0.0.0.0',
    port: 5900,
    wsPath: '/pw',
});
console.log("Running at", browserServer.wsEndpoint());
// results in ws://localhost:5900/pw

Client Configuration

export default defineConfig({
  ...
  use: {
    baseURL: 'http://localhost:5173',
    connectOptions: {
      wsEndpoint: 'ws://localhost:5900/pw',
      exposeNetwork: '<loopback>',  // have also tried 'localhost' and '*'
    }
  },
  ...
});

However, a simple test yields this error:

  1) [chromium] › example.spec.ts:3:1 › has title ──────────────────────────────────────────────────

    Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:5173/
    Call log:
      - navigating to "http://localhost:5173/", waiting until "load"

It seems that the mechanism that would enable the socks proxy (?) for localhost network access isn't working.

Ask

When running the client and server on different network segments, I'd expect to be able to use the exposeNetwork feature to reach resources on the "client" machine from the "server" machine. There appears to be support for this in the code, and I found this reference to the feature:

Is this a missing feature, something that could use more documentation, or just a total misunderstanding on my part?

dgozman commented 1 month ago

@parrotmac I think this feature is not implemented for the launchServer() method. Let me rephrase this issue as a feature request.

parrotmac commented 1 month ago

@dgozman sounds great, thank you! Do you happen to know if this is implemented in one of the adjacent launch* methods or otherwise in the public API?

mikestopcontinues commented 1 month ago

@dgozman, if you point me in the right direction, I'd be happy to make a PR. This is critical for me.