save changes
This commit is contained in:
@ -85,6 +85,45 @@ export async function disableCookiesInChrome(): Promise<WebDriver | null> {
|
||||
|
||||
}
|
||||
|
||||
export async function useChrome(): Promise<WebDriver | null> {
|
||||
// Set Chrome options
|
||||
const options = new chrome.Options();
|
||||
|
||||
// 1. Block all cookies
|
||||
//options.setUserPreferences({
|
||||
// 'profile.default_content_setting_values.cookies': 2, // 2 = Block all
|
||||
// 'profile.block_third_party_cookies': true
|
||||
//});
|
||||
|
||||
// 2. Optional: Launch in incognito for extra privacy
|
||||
options.addArguments('--incognito');
|
||||
options.addArguments('--start-maximized');
|
||||
|
||||
let driver: WebDriver | null = null;
|
||||
|
||||
try {
|
||||
driver = await new Builder()
|
||||
.forBrowser('chrome')
|
||||
.setChromeOptions(options)
|
||||
.build();
|
||||
|
||||
await driver.get('https://www.tripadvisor.com/');
|
||||
|
||||
console.log('Chrome launched with cookies disabled.');
|
||||
|
||||
// Optional: Verify cookies are blocked by trying to set/get a cookie
|
||||
await driver.manage().addCookie({ name: 'test', value: '123' });
|
||||
const cookies = await driver.manage().getCookies();
|
||||
console.log('Cookies after trying to add:', cookies); // Should be empty or restricted
|
||||
|
||||
return driver;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
return driver;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export async function useExistingChrome(): Promise<WebDriver> {
|
||||
// Connect to an existing Chrome browser running in debug mode on port 9222
|
||||
const options = new chrome.Options();
|
||||
|
||||
Reference in New Issue
Block a user