You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Chrome Options屏蔽Selenium自动登录Facebook后的通知弹窗?

Fix Facebook Notification Permission Popup in Selenium ChromeDriver

Got it, let's tackle that stubborn notification popup! The reason your alertBehavior: 'dismiss' setting isn't working is because this isn't a standard JavaScript alert—it's a browser permission prompt for notifications. Those are controlled by Chrome's content settings, not the alert behavior config.

Here are two solid ways to block or auto-handle these prompts:

1. Use Chrome Preferences to Block Notifications

You can directly set Chrome's default notification permission to "Block" using the prefs option in ChromeOptions. This will automatically deny any site's request to send notifications:

const {Builder, By, Key} = require('selenium-webdriver');
const {Options} = require('selenium-webdriver/chrome');

// Configure Chrome options to block notifications
const options = new Options()
  .setUserPreferences({
    'profile.default_content_setting_values.notifications': 2 // 2 = Block, 1 = Allow, 0 = Default
  });

let driver = new Builder()
  .forBrowser('chrome')
  .setChromeOptions(options)
  .build();

(async function demo() {
  await driver.get('https://www.facebook.com/');
  await driver.findElement(By.css('#email')).sendKeys('***');
  await driver.findElement(By.css('#pass')).sendKeys('***', Key.RETURN);
})();

2. Alternative: Use Experimental Chrome Options

If the above method doesn't work for your Chrome version, you can use a quick command-line flag to disable all notifications entirely in the browser session:

const {Builder, By, Key} = require('selenium-webdriver');
const {Options} = require('selenium-webdriver/chrome');

const options = new Options()
  .addArguments('--disable-notifications') // Disable all notification requests
  .addArguments('--disable-popup-blocking'); // Optional: Block other unwanted popups too

let driver = new Builder()
  .forBrowser('chrome')
  .setChromeOptions(options)
  .build();

(async function demo() {
  await driver.get('https://www.facebook.com/');
  await driver.findElement(By.css('#email')).sendKeys('***');
  await driver.findElement(By.css('#pass')).sendKeys('***', Key.RETURN);
})();

Key Notes:

  • For the preferences method, the value 2 tells Chrome to block all notification requests. If you ever wanted to auto-accept instead, you'd use 1; 0 keeps Chrome's default "ask user" behavior.
  • The --disable-notifications flag is a straightforward one-liner that turns off all notifications for the temporary Chrome session Selenium creates, which is perfect for avoiding this specific popup.

Either of these methods should stop that Facebook notification prompt from appearing. Just pick the one that works best with your Chrome and Selenium version!

内容的提问来源于stack exchange,提问作者Michael

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:01:13