4

I'm hosting a .NET Core HTTP application on localhost using Kestrel on an available port for some browser-based UI tests, but when trying to access it using real iOS devices with BrowserStack Automate with BrowserStackLocal.exe, Safari consistently refuses load the page.

I've tried various parts of the IP ranges documented here, but none have been successful. Desktop browsers (Chrome, IE, Edge and Firefox on Windows, Safari on macOS Mojave) and real Android devices work as expected.

I've also tried using the local IP address of the machine and the fully-qualified domain name (FQDN) as described here, but neither work portably as Windows Firewall blocks the connections even through BrowserStack Automate can resolve the address.

Port 80 is not a viable solution as developers' machines will have IIS running on their machines using that port, so it is not available for other purposes.

Given the following constraints, what are the workable solutions?

  1. Hosted on HTTP.
  2. Runs without admin privileges (i.e. no reconfiguring the firewall or using privileged port numbers <1024).
  3. At least two possible port numbers to use so that if one is in use there's at least one alternate to try.
  4. No additional manual setup required to run the tests (should just be the command dotnet test).
Martin Costello
  • 7,092
  • 4
  • 48
  • 62

5 Answers5

17

On the iOS devices, try resolving http://bs-local.com:5000 instead of http://localhost:5000.

Mukesh Tiwari
  • 814
  • 6
  • 7
10

You can access the site using http://bs-local.com:5000, But make sure to disable the host check for webpack using disableHostCheck: true in configuration.

For angular cli users, to disable to the host check you need to use --disable-host-check like ng serve --port 4200 --disable-host-check

Aniruddha Das
  • 14,517
  • 13
  • 83
  • 111
1

This is from BrowserStack's support:

a) On Safari

  • Previously, accessing local websites with 'localhost/127.0.0.1' in the URL was not supported on iOS devices running iOS versions 10 and above.

  • However, to make sure that your website loads with 'localhost' in the URL, we now modify the URL to http://bs-local.com on these devices. This helps in loading your website in an expected manner. The same is mentioned here.

  • In the screenshot you've shared, you can see the redirection to bs-local.com as well.

  • It seems that your localhost website is configured to be accessible only via specific hostnames such as 'localhost'. Thus, you face the reported error.

  • To be able to test your localhost website via Safari on iOS devices, I would recommend configuring your localhost website to be accessible via the private IP address of your local machine.

  • Once done, you can access your localhost website as http://<private_IP_address:port> and this should work.

  • I would also encourage reading through this guide to understand how you could achieve the above: https://www.notion.so/Testing-localhost-on-iOS-devices-1ceb5e274cee46d7ac538b71304919b4

b) On Chrome

  • Due to restrictions imposed by Safari, testing localhost websites on Chrome is not supported by default on iOS devices.

  • The problem arises with the usage of the domain 'localhost'. We are actively trying to find alternatives for this behavior as well.

  • However, in the meantime, you can access your localhost website via the private IP address as mentioned above via Chrome browser on iOS devices as well.

  • Once you make the necessary changes to your configuration to allow your localhost website to be accessible via the private IP address, you can test your localhost website via Chrome on iOS as well.

Feel free to reach out should you need any further assistance!

Note: The private IP address is not the same as 127.0.0.1. You can use this article to identify the private IP address of your machine.

Regards, Reehan BrowserStack Support

0

Did you try changing the 'localhost' with the IP address of the machine (where the web is hosted)?

For instance - If the IP for the machine on which application/webpage is hosted is 22.22.22.22, then change http://localhost:3000/index.html to http://22.22.22.22:3000/index.html in your test

They have mentioned the same here - https://www.browserstack.com/question/663

N3M
  • 266
  • 1
  • 3
  • I did, unfortunately both the FQDN and IP address fall fowl of Windows Firewall as described in the question. – Martin Costello Oct 29 '18 at 09:33
  • 1
    On the iOS devices, try resolving http://bs-local.com:5000 instead of http://localhost:5000. – Mukesh Tiwari Oct 29 '18 at 14:45
  • 1
    @MukeshTiwari Thank you - that fixed it! If you write this up as an answer, I'll mark it as the solution. Maybe this can be added to the documentation as a third troubleshooting suggestion on the question I posted the link to? – Martin Costello Oct 29 '18 at 18:32
0

If you are using Angular CLI then please run command

ng serve --host 0.0.0.0 --port xxxx 

This will make sure that you would be able to access application using your IP and port specified. Once done you should be able to access your application using browser stack iPhone device browsers using IP and port rather than localhost.

David Buck
  • 3,439
  • 29
  • 24
  • 31