async def launch_firefox_async(
    pw_instance: "AsyncPlaywrightContextManager",
    h3: bool,
    endpoint: Endpoint,
    warmup: bool,
    qlog: bool,
    pcap: bool,
    expnt_id: int,
    run_id: int,
) -> json:
    # set up firefox preference
    firefox_prefs = {}
    firefox_prefs["privacy.reduceTimerPrecision"] = False
    if h3:
        if qlog:
            firefox_prefs[
                "network.http.http3.enable_qlog"] = True  # enable qlog
        firefox_prefs[
            "network.http.http3.enabled"] = True  # enable h3 protocol
        firefox_prefs[
            "network.http.spdy.enabled.http2"] = False  # disable h2 protocol
        firefox_prefs[
            "network.http.spdy.enabled"] = False  # disable h1.1 protocol
        # the openlightspeed server works with a different h3 version than the rest of the servers

        port = endpoint.get_port()
        h3_version = "29"
        if endpoint.get_endpoint() == "server-openlitespeed":
            h3_version = "27"
        firefox_prefs[
            "network.http.http3.alt-svc-mapping-for-testing"] = f"{endpoint.port};h3-{h3_version}=:{port}"
    # attempt to launch browser
    try:
        if pcap:
            pcap_file = f"{os.getcwd()}/results/packets/async-{expnt_id}/firefox/{run_id}-{h3}.keys"
            return await pw_instance.firefox.launch(
                headless=True,
                firefox_user_prefs=firefox_prefs,
                env={"SSLKEYLOGFILE": pcap_file})
        else:
            return await pw_instance.firefox.launch(
                headless=True,
                firefox_user_prefs=firefox_prefs,
            )
    except Exception as e:  # if browser fails to launch, stop this request and write to the database
        logger.exception(str(e))
        return None
async def launch_edge_async(
    pw_instance: "AsyncPlaywrightContextManager",
    h3: bool,
    endpoint: Endpoint,
    warmup: bool,
    qlog: bool,
    pcap: bool,
    expnt_id: int,
    run_id: int,
) -> json:
    edge_args = []
    if (h3):
        edge_args = [
            "--enable-quic", "--quic-version=h3-29", "--disable-http2"
        ]
        domain = endpoint.get_domain()
        port = endpoint.get_port()
        edge_args.append(f"--origin-to-force-quic-on={domain}:{port}")
        if qlog:
            qlog_dir = f"{os.getcwd()}/results/async-qlogs/{expnt_id}/edge/"
            edge_args.append(f"--log-net-log={qlog_dir}/{run_id}.netlog")
    # attempt to launch browser
    try:
        if pcap:
            pcap_file = f"{os.getcwd()}/results/packets/async-{expnt_id}/edge/{run_id}-{h3}.keys"
            return await pw_instance.chromium.launch(
                headless=True,
                executable_path='/opt/microsoft/msedge-dev/msedge',
                args=edge_args,
                env={"SSLKEYLOGFILE": pcap_file})
        else:
            return await pw_instance.chromium.launch(
                headless=True,
                executable_path='/opt/microsoft/msedge-dev/msedge',
                args=edge_args,
            )
    except Exception as e:  # if browser fails to launch, stop this request and write to the database
        logger.error(str(e))
        return None
async def launch_chromium_async(
    pw_instance: "AsyncPlaywrightContextManager",
    h3: bool,
    endpoint: Endpoint,
    warmup: bool,
    qlog: bool,
    pcap: bool,
    expnt_id: int,
    run_id: int,
) -> json:
    chromium_args = []
    if h3:
        # set up chromium arguments for enabling h3, qlog, h3 version
        chromium_args = [
            "--enable-quic", "--quic-version=h3-29", "--disable-http2"
        ]
        domain = endpoint.get_domain()
        port = endpoint.get_port()
        chromium_args.append(f"--origin-to-force-quic-on={domain}:{port}")
        if qlog:
            # set up a directory results/qlogs/chromium/[experimentID] to save qlog
            qlog_dir = f"{os.getcwd()}/results/qlogs/async-{expnt_id}/chromium/"
            chromium_args.append(f"--log-net-log={qlog_dir}/{run_id}.netlog")
    # attempt to launch browser
    try:
        if pcap:
            pcap_file = f"{os.getcwd()}/results/packets/async-{expnt_id}/chromium/{run_id}-{h3}.keys"
            return await pw_instance.chromium.launch(
                headless=True,
                args=chromium_args,
                env={"SSLKEYLOGFILE": pcap_file})
        else:
            return await pw_instance.chromium.launch(
                headless=True,
                args=chromium_args,
            )
    except Exception as e:  # if browser fails to launch, stop this request and write to the database
        logger.error(str(e))
        return None