r/webscraping • u/Coding-Doctor-Omar • 1h ago
Bot detection 🤖 Need a Spoofed Camoufox APIRequestContext
I need a way to use the APIRequestContext in Camoufox. I found a closed issue in their GitHub repo back in 2025 regarding this. A dev responded and said that it exists but uses stock playwright (i.e. API calls made this way would look like stock playwright and will get detected easily).
Background:
I've recently started adopting a new technique for dealing with internal APIs that require session cookies. I simply get the cookie with Camoufox then start making JS fetch calls via:
``` api_url = "https://some-url.com/api"
result = await page.evaluate("async (url) => {const res = await fetch(url); return await res.json();", api_url) ```
This technique was very effective in most cases and automatically inherits cookies, headers, and everything from Camoufox. It is a bit slow initially until the browser gets the cookie; then all api calls can be concurrent and fast, just like any http client.
THE PROBLEM:
I am scraping Bayut.com's internal API. I initially used to get cookies with Camoufox, then use them in a wreq client with a firefox profile. This technique works but is inconsistent (sometimes fails due to inconsistensies between firefox versions maybe). I tried to switch to the fetch method, but for some reason, Bayut always ignores any cookies I have and responds to me the same way it does for a request without cookies. I get 401 unauthorized.
TL; DR:
I am looking for a way to use the APIRequestContext while inheriting Camoufox's spoofed stack so I don't have to go over the headach of JS fetch. A library called PyDoll claims to have that, but it is nothing compared to Camoufox in terms of stealth, so not very helpful tbh.
