Skip to content

Commit 0ade792

Browse files
authored
Fix browser and request language with full DOM fetcher (#1226)
2 parents b106793 + 831ea82 commit 0ade792

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## Unreleased [patch]
6+
7+
> Development of this release was supported by [Reset Tech](https://www.reset.tech).
8+
9+
### Fixed
10+
11+
- Fix browser and request language with full DOM fetcher
12+
513
## 10.3.0 - 2026-01-12
614

715
> Development of this release was made on a volunteer basis by [@Ndpnt](http://github.com/ndpnt).

src/archivist/fetcher/fullDomFetcher.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import stealthPlugin from 'puppeteer-extra-plugin-stealth';
33

44
import { resolveProxyConfiguration, extractProxyCredentials } from './proxyUtils.js';
55

6-
puppeteer.use(stealthPlugin());
7-
86
let browser;
97

108
export default async function fetch(url, cssSelectors, config) {
9+
puppeteer.use(stealthPlugin({ locale: config.language }));
10+
1111
let context;
1212
let page;
13+
let client;
1314
let response;
1415
const selectors = [].concat(cssSelectors);
1516

@@ -25,6 +26,14 @@ export default async function fetch(url, cssSelectors, config) {
2526
await page.setDefaultNavigationTimeout(config.navigationTimeout);
2627
await page.setExtraHTTPHeaders({ 'Accept-Language': config.language });
2728

29+
// Use CDP to ensure the browser language is set correctly (most reliable method, see https://zirkelc.dev/posts/puppeteer-language-experiment)
30+
client = await page.createCDPSession();
31+
32+
await client.send('Network.setUserAgentOverride', {
33+
userAgent: await browser.userAgent(),
34+
acceptLanguage: config.language,
35+
});
36+
2837
if (browser.proxyCredentials?.username && browser.proxyCredentials?.password) {
2938
await page.authenticate(browser.proxyCredentials);
3039
}
@@ -73,6 +82,9 @@ export default async function fetch(url, cssSelectors, config) {
7382
}
7483
throw new Error(error.message);
7584
} finally {
85+
if (client) {
86+
await client.detach();
87+
}
7688
if (page) {
7789
await page.close();
7890
}

0 commit comments

Comments
 (0)