The wait_for_server function, defined in grip/browser.py, waits until a local server starts listening on a given host and port. It repeatedly checks using is_server_running, sleeping for 0.1 seconds between attempts. If a cancel_event is provided and set, it exits early. It returns True when the server is ready. This function is used in wait_and_start_browser to ensure the server is running before opening the browser.