'cf' object not being set

It is mentioned in the docs that the cf object would always be available on the request object.

However, my worker sometimes throws an error saying Cannot read property 'country of undefined', where undefined is supposed to be the cf object of the request.

Now, I also have the following page rules set up for that domain (just in case) : IP Geolocation and True client IP header but I still don’t get the cf object on my request.

Any suggestions ?

Really odd, I’d recommend logging the “cf-ray” [request] header (if you don’t already) and support might be able to track down the issue . I’ve never seen this happen but I have a relatively low volume of requests coming in to my workers.

Is every request guaranteed to have a cf.country? Are you just not getting the country field? I would assume that they probably can’t confidently match every IP address to a country.

This makes it seem like the cf object itself isn’t being set

but that might be an issue with CF’s v8 implementation, so i’d agree that you should add a check/test for other properties of cf like colo or httpProtocol.

1 Like

It seems that the cf object is null. Here’s the complete request object:


Where are you editing the worker from? the request.cf object isn’t set in the dashboard editor or cloudflareworkers.com, it’s only set if you use wrangler dev or if the worker is published to the workers.dev subdomain or a custom domain


If you have any more questions, I would recommend you join the Workers discord server

Workers Preview editor doesn’t have a cf object.

A forum/social website that isn’t mine, uses cf_country header, to echo every user’s “real location”/recent login vs user set location as an anti fraud measure. Certain VPNs or enterprise ASNs or cloud hosting ASNs return “UNKNOWN” in the UI. I dont know what on a JSON or HTTP level, what “UNKNOWN” in the UI is on the wire but the CF geolocation product DOES NOT default to ICAN/ARIN AS Org Address if no further info is available, it returns an error instead.