# Disable Browser Notifications and Pop-ups v1.2
# Chrome, Edge, Firefox - Windows 11
# Exit 0 = Success
# Exit 1001 = One or more installed browsers failed
# Notifications blocked, notification prompt requests blocked, Existing notification allow-list policies removed, existing pop-up allow-list entries preserved
Write-Host "Disabling browser notification prompts, notifications, pop-ups, and redirects..."
$FailureDetected = $false
function Set-BrowserSecurityPolicy {
param (
[string]$BrowserName,
[string]$PolicyPath,
[string[]]$NotificationAllowListPolicyPaths
)
try {
if (-not (Test-Path $PolicyPath)) {
New-Item -Path $PolicyPath -Force | Out-Null
}
# Block notification prompts and notifications
New-ItemProperty `
-Path $PolicyPath `
-Name "DefaultNotificationsSetting" `
-PropertyType DWord `
-Value 2 `
-Force | Out-Null
# Block pop-ups and redirects
New-ItemProperty `
-Path $PolicyPath `
-Name "DefaultPopupsSetting" `
-PropertyType DWord `
-Value 1 `
-Force | Out-Null
# Remove notification allow-list policies only
foreach ($AllowListPath in $NotificationAllowListPolicyPaths) {
if (Test-Path $AllowListPath) {
Remove-Item -Path $AllowListPath -Recurse -Force
}
}
$NotificationValue = Get-ItemPropertyValue `
-Path $PolicyPath `
-Name "DefaultNotificationsSetting" `
-ErrorAction Stop
$PopupValue = Get-ItemPropertyValue `
-Path $PolicyPath `
-Name "DefaultPopupsSetting" `
-ErrorAction Stop
if (($NotificationValue -eq 2) -and ($PopupValue -eq 1)) {
Write-Host "$BrowserName notification prompts, notifications, pop-ups, and redirects configured."
}
else {
throw "$BrowserName policy verification failed."
}
}
catch {
Write-Host "ERROR: Failed to configure $BrowserName browser security policies."
$script:FailureDetected = $true
}
}
# Chrome
$ChromeInstalled = (Test-Path "HKLM:\SOFTWARE\Google\Chrome") -or `
(Test-Path "HKLM:\SOFTWARE\WOW6432Node\Google\Chrome") -or `
(Test-Path "$Env:ProgramFiles\Google\Chrome\Application\chrome.exe") -or `
(Test-Path "${Env:ProgramFiles(x86)}\Google\Chrome\Application\chrome.exe")
if ($ChromeInstalled) {
Set-BrowserSecurityPolicy `
-BrowserName "Chrome" `
-PolicyPath "HKLM:\SOFTWARE\Policies\Google\Chrome" `
-NotificationAllowListPolicyPaths @(
"HKLM:\SOFTWARE\Policies\Google\Chrome\NotificationsAllowedForUrls"
)
}
else {
Write-Host "Chrome not detected. Skipping."
}
# Edge
$EdgeInstalled = (Test-Path "HKLM:\SOFTWARE\Microsoft\Edge") -or `
(Test-Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Edge") -or `
(Test-Path "$Env:ProgramFiles\Microsoft\Edge\Application\msedge.exe") -or `
(Test-Path "${Env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe")
if ($EdgeInstalled) {
Set-BrowserSecurityPolicy `
-BrowserName "Edge" `
-PolicyPath "HKLM:\SOFTWARE\Policies\Microsoft\Edge" `
-NotificationAllowListPolicyPaths @(
"HKLM:\SOFTWARE\Policies\Microsoft\Edge\NotificationsAllowedForUrls"
)
}
else {
Write-Host "Edge not detected. Skipping."
}
# Firefox
$FirefoxInstalled = $false
$FirefoxPaths = @(
"$Env:ProgramFiles\Mozilla Firefox",
"${Env:ProgramFiles(x86)}\Mozilla Firefox"
)
foreach ($FirefoxPath in $FirefoxPaths) {
if (Test-Path $FirefoxPath) {
$FirefoxInstalled = $true
try {
$DistributionPath = Join-Path $FirefoxPath "distribution"
if (-not (Test-Path $DistributionPath)) {
New-Item -Path $DistributionPath -ItemType Directory -Force | Out-Null
}
$PoliciesFile = Join-Path $DistributionPath "policies.json"
$PoliciesJson = @"
{
"policies": {
"DisableNotifications": true,
"Permissions": {
"Block": {
"Popup": true
}
}
}
}
"@
$PoliciesJson | Out-File -FilePath $PoliciesFile -Encoding UTF8 -Force
if (Test-Path $PoliciesFile) {
Write-Host "Firefox notification prompts, notifications, and pop-ups disabled at $FirefoxPath."
}
else {
throw "Firefox policies.json was not created."
}
}
catch {
Write-Host "ERROR: Failed to configure Firefox browser security policies at $FirefoxPath."
$FailureDetected = $true
}
}
}
if (-not $FirefoxInstalled) {
Write-Host "Firefox not detected. Skipping."
}
if ($FailureDetected) {
Write-Host "One or more installed browsers failed configuration."
exit 1001
}
else {
Write-Host "All installed browsers configured successfully."
exit 0
}