Created
November 14, 2019 15:02
-
-
Save karstennilsen/9ddc511fa1f6a474662e7e52568f985b to your computer and use it in GitHub Desktop.
Google Chrome Disable Occlusion in Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$GooglePolicyObj = $null | |
$GooglePolicyObj = Get-ItemProperty -Path HKCU:\SOFTWARE\Policies\Google\Chrome -Name "UserDataDir" | |
$GoogleUserDir = $env:LOCALAPPDATA + "\Google\Chrome\User Data" | |
if ($GooglePolicyObj -ne $null) { | |
$GoogleUserDir = $GooglePolicyObj.UserDataDir -replace "\$\{documents\}", [Environment]::GetFolderPath("MyDocuments") | |
} | |
$jsonPath = $GoogleUserDir + "\Local State" | |
if (![System.IO.File]::Exists($jsonPath)) { | |
Write-Host ($jsonPath + " does not exist, strange") | |
return | |
} | |
Write-Host ("Local State .json location: " + $jsonPath) | |
$jsonRaw = Get-Content -Raw -Path ($jsonPath) | |
$jsonRaw = $jsonRaw -replace "`"`":", "`"ReplaceBackToEmpty684`":" | |
$json = $jsonRaw | ConvertFrom-Json | |
if ($json.browser -eq $null) { | |
# Create browser boject with, enabled_labs_experiments object | |
$browser = New-Object PSObject | |
$browser | add-member -NotePropertyName enabled_labs_experiments -NotePropertyValue "-" | |
$browser.enabled_labs_experiments = @("web-contents-occlusion@2") | |
$json | add-member -NotePropertyName browser -NotePropertyValue $browser | |
} else { | |
if ($json.browser.enabled_labs_experiments -eq $null) { | |
# Create enabled_labs_experiments object | |
$json.browser | add-member -NotePropertyName enabled_labs_experiments -NotePropertyValue "-" | |
$json.browser.enabled_labs_experiments = @("web-contents-occlusion@2") | |
} else { | |
# Patch existing enabled_labs_experiments object | |
if (($json.browser.enabled_labs_experiments.GetType()).BaseType.ToString() -eq "System.Array") { | |
if ($json.browser.enabled_labs_experiments.Contains("web-contents-occlusion@2")) { | |
"Occlusion already patched" | |
} else { | |
if (($json.browser.enabled_labs_experiments.GetType()).BaseType.ToString() -eq "System.Array") { | |
# Patch occlusion | |
# Add to array | |
$json.browser.enabled_labs_experiments += "web-contents-occlusion@2" | |
} | |
} | |
} else { | |
# Patch occlusion | |
$json.browser.enabled_labs_experiments = @("web-contents-occlusion@2") | |
} | |
} | |
} | |
Copy-Item $jsonPath ($jsonPath+".bak") -Force | |
$jsonRaw = $json | convertto-json -Compress -depth 100 | |
$jsonRaw -replace "`"ReplaceBackToEmpty684`":", "`"`":" | out-file $jsonPath -Encoding utf8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment