使用jsselenium-webdriver 添加 option启动excludeSwitches useAutomationExtension并且执行execute_cdp_cmd
以下是使用JavaScript和selenium-webdriver添加option启动excludeSwitches和useAutomationExtension,并执行execute_cdp_cmd的示例代码:
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const { Options } = require('selenium-webdriver/chrome');
// Create Chrome options object
const chromeOptions = new Options();
// Add excludeSwitches and useAutomationExtension options
chromeOptions.excludeSwitches('enable-automation');
chromeOptions.setUseAutomationExtension(false);
// Create driver with Chrome options
const driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(chromeOptions)
.build();
// Execute CDP command
driver.executeCdpCommand('Page.addScriptToEvaluateOnNewDocument', {
source: 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})'
});
// Example usage: navigate to a website
driver.get('https://www.google.com');
``
原文地址: https://www.cveoy.top/t/topic/gEuC 著作权归作者所有。请勿转载和采集!