When the url field is the redirect, not the page
If you pipe a search result's url into fetch() and let it follow redirects, 24 of the 29 rows I pulled this morning reach google.com before anything else. I did not pick the wrong field out of carelessness. The response
If you pipe a search result's url into fetch() and let it follow redirects, 24 of the 29 rows I pulled this morning reach google.com before anything else. I did not pick the wrong field out of carelessness. The response offers five fields that look like a link, and in my data none of them is the page address on its own.
I collected three POST /google/search responses: two pages for the query "undici fetch timeout AbortSignal" (page:1, page:2) and one page:1 for "postgres jsonb index not used". Together they hold 29 organic rows, 10, 10 and 9. Five fields per row look addressable: link, url, source_url, display_url, display_link. Across those 29 rows, url and link were byte-for-byte identical 29 times out of 29. The official field table says url carries the normalized result link and is usually the same as link. In my three responses it was the same every single time, which makes url a copy and not a repair.
Disclosure: this post was drafted with an AI assistant and checked line by line against real API responses. Every number below was re-read from the saved JSON.
Check one: 24 of the 29 links start on google.com
Counting organic[].link per response, 7 of 10 on the first one, 9 of 10 on the second, 8 of 9 on the third begin with the www.google.com/goto?url= prefix. That is 24 wrappers out of 29 rows. The remaining five are real addresses: two on github.com, one on stackoverflow.com, one on community.fly.io, one on michael.otacoo.com. So the host distribution of the raw link field looks like five sites plus a redirector that outweighs all of them combined.
If your pipeline inserts link into a table and calls it done, 82 percent of the rows in my sample store a Google redirect with a long opaque token, not a page. Those tokens are also long enough to bloat a dedupe key: the url= parameter runs from 139 to 255 characters.
Check two: url equals link, 29 out of 29
I ran a strict equality test on organic[].url === organic[].link, with no normalization on either side. It passed for all 29 rows. The first two responses were fully wrapped at 10 of 10 for this comparison, the third at 9 of 9.
This is the part that changes how I read the field table. url sounds like the place where a parser would put the resolved target and link the raw one. My responses do not show that split at all: the two fields are the same string, so url inherits every wrapper link has. Anyone who switches from link to url to escape the redirects gets the same redirects, now with a false sense of having normalized something.
Check three: display_url fails new URL() 29 out of 29
display_url is the field people reach for when they want a readable host. Passing all 29 values to new URL() threw on every one. The three shapes behind that:
- 23 rows carry the U+203A pointer character as a path separator, for example a
github.comissue URL broken intonodejs,undiciandissuessegments. - 8 rows end in
..., truncated mid-path, for example arinblog.orgpath cut afterjavascript-fetc. - 6 rows do not start with
httpat all, for examplemedium.com.
Those three groups overlap, which is why they sum past 29. The field is a display string assembled for eyes on a screen. It is not a URL and was never meant to survive a parse.
display_link is the Google presentation text, and I did not build any branch on it.
source_url decodes to bytes, not to addresses
source_url is present on all 29 rows. Taking the url= parameter as base64url, all 29 decode to bytes, so the encoding is honest. What comes out is not an address: 0 of the 29 decoded buffers contain the substring http. The first token is 143 characters and yields 107 bytes, 0.36 of them printable, starting with 0801126701c42245d7c518a1220005a4. That looks like a serialized redirect record.
The practical reading: decoding the token offline is not a shortcut to the destination. Reaching the page requires a network hop, so either you follow redirects yourself or you hand the links to something that does.
The field table I wish the docs had
| field | type | what I measured in these responses |
|---|---|---|
link |
string | 24 of 29 are www.google.com/goto?url= wrappers, 5 are direct |
url |
string | identical to link on 29 of 29 rows |
source_url |
string | present on 29 of 29, decodes to bytes, 0 contain http
|
display_url |
string | unparsable on 29 of 29, 23 use U+203A, 8 end in ..., 6 lack a scheme |
display_link |
string | presentation text, not treated as a link by my script |
position |
number | the block index on the page, shared by every row in that block |
rank |
number | 1-based index inside the block, the one to sort by |
The position and rank split matters for the same reason the link fields do. In my third response position read 1, 2, 4, 5, 6, 7, 8, 9, 10 while rank read 1 through 9. If you sort on position you get block order with a gap; rank is the field that gives you the order the rows appear in. I did not find an explanation for the gap, so I am only reporting that it showed up there.
The twenty-line check I run before trusting any field
This needs one saved response file and no credentials. Point it at a /google/search body you already have.
const raw = require('./resp.json');
const org = raw.data.organic;
const stats = {
total: org.length,
urlEqualsLink: org.filter(o => o.url === o.link).length,
wrapped: org.filter(o => new URL(o.link).host === 'www.google.com').length,
displayUrlUnparsable: org.filter(o => { try { new URL(o.display_url); return false } catch { return true } }).length,
missingDate: org.filter(o => !o.date && !o.published_at).length,
};
console.log(stats);
async function follow(u, hops = 0) {
const r = await fetch(u, { redirect: 'manual', signal: AbortSignal.timeout(15000) });
const loc = r.headers.get('location');
if (!loc) return { hops, status: r.status, final: u };
return follow(new URL(loc, u).href, hops + 1);
}
Against my first response it printed total: 10, urlEqualsLink: 10, wrapped: 7, displayUrlUnparsable: 10, missingDate: 2. Running follow() on the first wrapped link returned hops: 3, status: 200 and the destination rinblog.org/javascript-fetch-api-update/ at 70,733 bytes. The three hops were www.google.com/goto, then www.google.com.hk/url with pref=hkredirect, then www.google.com.hk/goto. The redirect crosses from the .com host to the .com.hk host, which is why a client capped at two redirects gives up on a link that works fine in a browser.
Following by hand, or handing the links over
Two options, and the choice depends on how many links you have and how much you want to depend on one extra call.
Doing it by hand with redirect: 'manual' costs one function and no extra service. It is the right call for a handful of links, for debugging, and for any pipeline that already has timeout and retry logic around fetch(). Set the redirect budget to at least three, or you will log a failure that is really a budget of two.
The batched option earns its place once you have a page of results. Sending those 24 wrapper links as one POST /google/resolve call with a links array returned 24 entries, every one of them marked resolved. The 24 resolved URLs collapse to 22 distinct ones. Add the 5 direct links and the 29 rows become 27 distinct pages across 16 hosts, against 5 hosts if you count the raw link field. The wrappers were hiding duplicates: two different links of 194 and 195 characters resolve to the same qiita.com page, and two more of 284 and 286 characters resolve to the same medium.com page. I could not see that from the raw field at all.
I still count the hops myself when something breaks, because the resolver tells me where a link went, not why a fetch failed.
The JSON I measured came from calls to a SERP endpoint; the same shapes appear in any response that carries these fields. serpbase.dev is where mine came from, and the numbers above are the fields I read back from those saved responses.
What this changes in a pipeline
For a crawler that feeds articles into storage, the useful order is: check whether the field exists, check whether the sibling keys you depend on are populated, then resolve before insert. Sorting and dedupe belong on the resolved URL, and the redirect field is worth keeping as provenance rather than as a key. Every number here comes from three responses to two queries on one morning, so treat it as a shape to test for, not a constant.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.