function setUserAgent
setUserAgent(
httpService: HttpService,
session: { toJSON(expression: string): Promise<string | null>; }
): Promise<void>

Replaces the default user-agent with the page's own, which is the one a server should see.

The constant in DEFAULT_HEADERS goes stale the moment Chrome ships a version; the page in front of this session knows the real one. Headless comes out of it because a server that behaves differently for a robot would behave differently for a prompt, and the prompt is a person — the rest of the string is left exactly as the browser wrote it.

Only ever replaces the default: a session that has already said .header user-agent=… means it.

import { setUserAgent, create } from './http-service.ts';

const httpService = create();
await setUserAgent(httpService, { toJSON: () => Promise.resolve('"Mozilla/5.0 (Chrome)"') });
httpService.headers.get('user-agent'); // 'Mozilla/5.0 (Chrome)'

Parameters

httpService: HttpService
session: { toJSON(expression: string): Promise<string | null>; }

Return Type

Promise<void>

Usage

import { setUserAgent } from "lib/repl/http-service.ts";