diff --git a/packages/playwright-core/src/utils/happy-eyeballs.ts b/packages/playwright-core/src/utils/happy-eyeballs.ts index e17d6a7026..936dfb739d 100644 --- a/packages/playwright-core/src/utils/happy-eyeballs.ts +++ b/packages/playwright-core/src/utils/happy-eyeballs.ts @@ -130,7 +130,7 @@ function clientRequestArgsToHostName(options: http.ClientRequestArgs): string { if (options.hostname) return options.hostname; if (options.host) - return options.host.split(':')[0]; + return options.host; throw new Error('Either options.hostname or options.host must be provided'); } diff --git a/tests/library/browsercontext-fetch-happy-eyeballs.spec.ts b/tests/library/browsercontext-fetch-happy-eyeballs.spec.ts index 9de9cd058a..a7e66e5cc7 100644 --- a/tests/library/browsercontext-fetch-happy-eyeballs.spec.ts +++ b/tests/library/browsercontext-fetch-happy-eyeballs.spec.ts @@ -60,3 +60,9 @@ it('https post should work with ignoreHTTPSErrors option', async ({ context, htt expect(interceptedHostnameLookup).toBe('localhost'); }); + +it('should work with ip6 and port as the host', async ({ request, server }) => { + const response = await request.get(`http://[::1]:${server.PORT}/simple.json`); + expect(response.url()).toBe(`http://[::1]:${server.PORT}/simple.json`); + expect(response).toBeOK(); +});