Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

Improved hide navigator hiding trick.

Petr Patek0f9d563e0096
diff --git a/src/stealth/hiding_tricks.js b/src/stealth/hiding_tricks.js
index 5fc6ae01e..f5ff5e748 100644
--- a/src/stealth/hiding_tricks.js
+++ b/src/stealth/hiding_tricks.js
@@ -1,10 +1,16 @@
/* istanbul ignore file */
const hideWebDriver = () => {
- const newProto = window.navigator.__proto__; // eslint-disable-line
- delete newProto.webdriver;
- // eslint-disable-next-line
- navigator.__proto__ = newProto
+ Object.defineProperty(window, 'navigator', {
+ value: new Proxy(navigator, {
+ has: (target, key) => (key === 'webdriver' ? false : key in target),
+ get: (target, key) => (key === 'webdriver' // eslint-disable-line
+ ? undefined
+ : typeof target[key] === 'function'
+ ? target[key].bind(target)
+ : target[key]),
+ }),
+ });
};
const hackPermissions = () => {