Skip to content

[Feedback]: Disable DNS over HTTPS (DoH) in Firefox/Camoufox preferences to respect local /etc/hosts and prevent crashes #186

@lofojak

Description

@lofojak

Deployment Platform

None

Version

v1.2.5

Client/Tool

Problem not in client, i checked in logs/web

API Endpoint

None

Issue/Request Description

Describe the bug

When running the application, the browser (Camoufox/Firefox) bypasses the operating system's local DNS resolver (including the /etc/hosts file).

If a user relies on /etc/hosts to route or bypass blocks for aistudio.google.com domain, the browser ignores these rules because DNS over HTTPS (DoH) is enabled by default. This leads to connection failures or ISP blocking pages, which triggers an unhandled pageerror inside Playwright, causing a fatal crash:
TypeError: Cannot read properties of undefined (reading 'url') in FFBrowserContext.

Cause

By default, Firefox-based browsers use their own encrypted DNS resolver (Trusted Recursive Resolver / TRR), which ignores /etc/hosts.

Solution

We can force the browser to respect the system's DNS settings and the /etc/hosts file by explicitly disabling DoH in the launch preferences.

Adding the following preferences to firefoxUserPrefs solves the issue:

  • "network.trr.mode": 5 (completely disables TRR/DoH)
  • "network.trr.uri": "" (clears the DoH endpoint)

Proposed Code Change

In the browser launch configuration (e.g., where playwright.firefox.launch is called), please add these options to firefoxUserPrefs:
in file ./src/core/BrowserManager.js, at line 82..116

this.firefoxUserPrefs = {
            ... /-some lines -/ ...
            "media.autoplay.default": 5, // 5 = Block all autoplay
            "media.volume_scale": "0.0", // Mute audio
            "network.trr.mode": 5,
            'network.trr.uri': '',
            "network.dns.disablePrefetch": true, // Disable DNS prefetching
            "network.http.speculative-parallel-limit": 0, // Disable speculative connections
            "network.prefetch-next": false, // Disable link prefetching
            "permissions.default.geo": 0, // 0 = Always deny geolocation
            ... /-some lines -/ ...
        };

Logs (Optional)

[INFO] [System] HTTP server is listening on http://0.0.0.0:10809
[INFO] [System] Keep-Alive timeout set to 120 seconds.
[INFO] [System] WebSocket server is listening on ws://0.0.0.0:9998
[INFO] [System] Proxy server system startup complete.
[INFO] [System] No valid startup index specified, will activate first available context [0].
[INFO] [System] Starting context pool (maxContexts=2)...
[INFO] 🚀 [ContextPool] Starting pool preload (pool=2, order=[0, 1, 2])...
[INFO] 🚀 [Browser] Launching main browser instance...
[INFO] ✅ [Browser] Main browser instance launched successfully.
[INFO] [ContextPool] Initializing context #0...
[INFO] [Entrypoint] Received a request: GET /api/auth/config
[INFO] [Context#0] Privacy protection layer active: ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 Ti Di>
[INFO] [Context#0] Privacy protection layer active: ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 Ti Di>
[INFO] [Auth] Successful login from IP: 127.0.0.1
[INFO] [Entrypoint] Received a request: GET /api/version/check
[INFO] [Context#0] Found "Continue to the app" button, clicking...
[INFO] [Context#0] No Launch button found
[INFO] [Context#0] ⏳ Waiting for WebSocket initialization (timeout: 120s)...
[INFO] [Context#0] ✅ authIndex received from parent: 0
[INFO] [Context#0] System initializing...
[INFO] [Context#0] Connecting to server: ws://127.0.0.1:9998?authIndex=0
[INFO] [Server] Internal WebSocket client connected (from: 127.0.0.1, authIndex: 0)
[INFO] [Context#0] ✅ Connection successful!
[INFO] [Context#0] System initialization complete, waiting for server instructions...
[INFO] [Auth Update] 💾 Successfully updated auth credentials for account #0
[INFO] ✅ [ContextPool] First context #0 ready.
[INFO] [ContextPool] Background preload will try [1, 2] to reach pool size 2 (need 1 more)
[INFO] [ContextPool] Background preload starting for [1, 2] (poolCap=2)...
[INFO] [ContextPool] Background preload init context #1...
[INFO] ==================================================
[INFO] ⚡ [FastSwitch] Switching to pre-loaded context for account #0
[INFO] ==================================================
[INFO] [Context#0] 🛡️ Background health monitor service (Scavenger) started...
[INFO] [Browser] ⚡ Sending active trigger request to Launch flow...
[INFO] ✅ [FastSwitch] Switched to account #0 instantly!
[INFO] [System] ✅ Successfully activated account #0!
[INFO] [Context#1] Privacy protection layer active: ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 Ti Di>
[INFO] [Context#1] Privacy protection layer active: ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 Ti Di>
[INFO] [Browser] 🛡️ Background Wakeup Service (Rocket Handler) started...
[INFO] [Context#0] Connecting to server: ws://127.0.0.1:9998?authIndex=0
[INFO] [Server] Internal WebSocket client connected (from: 127.0.0.1, authIndex: 0)
[INFO] [Context#0] ✅ Connection successful!
[INFO] [Context#0] System initialization complete, waiting for server instructions...
[INFO] [Auth Update] 💾 Successfully updated auth credentials for account #0
[INFO] ✅ [ContextPool] First context #0 ready.
[INFO] [ContextPool] Background preload will try [1, 2] to reach pool size 2 (need 1 more)
[INFO] [ContextPool] Background preload starting for [1, 2] (poolCap=2)...
[INFO] [ContextPool] Background preload init context #1...
[INFO] ==================================================
[INFO] ⚡ [FastSwitch] Switching to pre-loaded context for account #0
[INFO] ==================================================
[INFO] [Context#0] 🛡️ Background health monitor service (Scavenger) started...
[INFO] [Browser] ⚡ Sending active trigger request to Launch flow...
[INFO] ✅ [FastSwitch] Switched to account #0 instantly!
[INFO] [System] ✅ Successfully activated account #0!
[INFO] [Context#1] Privacy protection layer active: ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 Ti Di>
[INFO] [Context#1] Privacy protection layer active: ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 Ti Di>
[INFO] [Browser] 🛡️ Background Wakeup Service (Rocket Handler) started...
[WARN] [VersionChecker] Failed to fetch tags: timeout of 10000ms exceeded
[INFO] [Context#1] Found "Continue to the app" button, clicking...
[INFO] [Context#1] No Launch button found
[INFO] [Context#1] ⏳ Waiting for WebSocket initialization (timeout: 120s)...
./AIStudioToAPI/node_modules/playwright-core/lib/coreBundle.js:49624
              url: pageError.location.url,
                                      ^
TypeError: Cannot read properties of undefined (reading 'url')
    at FFBrowserContext.<anonymous> (./AIStudioToAPI/node_modules/playwright-core/lib/coreBundle.js:49624:39)
    at FFBrowserContext.emit (node:events:524:28)
    at _Page.emitOnContext (./AIStudioToAPI/node_modules/playwright-core/lib/coreBundle.js:19815:29)
    at _Page.addPageError (./AIStudioToAPI/node_modules/playwright-core/lib/coreBundle.js:19951:16)
    at FFPage._onUncaughtError (./AIStudioToAPI/node_modules/playwright-core/lib/coreBundle.js:43470:20)
    at FFSession.emit (node:events:524:28)
    at ./AIStudioToAPI/node_modules/playwright-core/lib/coreBundle.js:42785:45
Node.js v20.19.2
aistudiotoapi.service: Main process exited, code=exited, status=1/FAILURE
aistudiotoapi.service: Failed with result 'exit-code'.
aistudiotoapi.service: Consumed 56.187s CPU time, 2.4G memory peak.
Started aistudiotoapi.service - AIStudioToAPI Service.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✨ FeatureNew feature or implementation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions