Replies: 2 comments 1 reply
-
Hi! I know why these errors occur. THe logic is that I download .xpi file, expand the manifest from it and parse it to get the ID. "browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "57.0"
}
}, As you may see the structure is A little bit later I may rewrite the code for your extensions to make it work. For example |
Beta Was this translation helpful? Give feedback.
-
<#
.SYNOPSIS
Add extensions to Firefox automatically
.PARAMETER ExtensionUri
Copy URL on an extesion page by right-clicking on the Download button
.PARAMETER Hive
HKLM affects every user of a machine, HKCU will affect only the primary user
.EXAMPLE
$Parameters = @{
ExtensionUris = @("https://addons.mozilla.org/firefox/downloads/file/3816867/ublock_origin.xpi")
Hive = "HKCU"
}
New-FirefoxExtension @Parameters
.NOTES
Some extensions doesn't have an appropriate ID to extract from manifest. This means that they cannot be installed programmatically. You need to know their ID
.NOTES
Enable extension manually
#>
function Add-FirefoxExtension
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string[]]
$ExtensionUris,
[Parameter(Mandatory = $false)]
[ValidateSet("HKCU", "HKLM")]
[string]
$Hive
)
foreach ($Uri in $ExtensionUris)
{
# Downloading extension
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Extension = Split-Path -Path $Uri -Leaf
$Parameters = @{
Uri = $Uri
OutFile = "$DownloadsFolder\$Extension"
Verbose = [switch]::Present
}
Invoke-WebRequest @Parameters
# Copy file and rename it into .zip
Get-Item -Path "$DownloadsFolder\$Extension" -Force | Foreach-Object -Process {
$NewName = $_.FullName -replace ".xpi", ".zip"
Copy-Item -Path $_.FullName -Destination $NewName -Force
}
<#
.SYNOPSIS
Expand the specific file from ZIP archive. Folder structure will be created recursively
.Parameter Source
The source ZIP archive
.Parameter Destination
Where to expand file
.Parameter File
Assign the file to expand
.Example
ExtractZIPFile -Source "D:\Folder\File.zip" -Destination "D:\Folder" -File "Folder1/Folder2/File.txt"
#>
function ExtractZIPFile
{
[CmdletBinding()]
param
(
[string]
$Source,
[string]
$Destination,
[string]
$File
)
Add-Type -Assembly System.IO.Compression.FileSystem
$ZIP = [IO.Compression.ZipFile]::OpenRead($Source)
$Entries = $ZIP.Entries | Where-Object -FilterScript {$_.FullName -eq $File}
$Destination = "$Destination\$(Split-Path -Path $File -Parent)"
if (-not (Test-Path -Path $Destination))
{
New-Item -Path $Destination -ItemType Directory -Force
}
$Entries | ForEach-Object -Process {[IO.Compression.ZipFileExtensions]::ExtractToFile($_, "$($Destination)\$($_.Name)", $true)}
$ZIP.Dispose()
}
$Parameters = @{
Source = "$DownloadsFolder\$Extension"
Destination = "$DownloadsFolder"
File= "manifest.json"
}
ExtractZIPFile @Parameters
# Get the author id
$manifest = Get-Content -Path "$DownloadsFolder\manifest.json" -Encoding Default -Force | ConvertFrom-Json
# Some extensions don't have valid JSON manifest
if ($manifest.applications)
{
$ApplicationID = $manifest.applications.gecko.id
}
if ($manifest.browser_specific_settings)
{
$ApplicationID = $manifest.browser_specific_settings.gecko.id
}
# These extensions don't have a valid manifest. We need to know their ID before moving to the extension folder
switch ($Extension)
{
"7tv.xpi"
{
$ApplicationID = "{7ef0f00c-2ebe-4626-8ed7-3185847fcfad}"
}
"clearurls.xpi"
{
$ApplicationID = "{74145f27-f039-47ce-a470-a662b129930a}"
}
"flagfox.xpi"
{
$ApplicationID = "{1018e4d6-728f-4b20-ad56-37578a4de76b}"
}
"traduzir_paginas_web.xpi"
{
$ApplicationID = "{036a55b4-5e72-4d05-a06c-cba2dfcc134a}"
}
"universal_bypass.xpi"
{
$ApplicationID = "{529b261b-df0b-4e3b-bf42-07b462da0ee8}"
}
"video_ad_block_for_twitch.xpi"
{
$ApplicationID = "{3385c2d8-dcfd-4f92-adb7-5d8429dee164}"
}
}
Get-Item -Path "$DownloadsFolder\$Extension" -Force | Rename-Item -NewName "$ApplicationID.xpi" -Force
# Getting Firefox profile name
$String = (Get-Content -Path "$env:APPDATA\Mozilla\Firefox\installs.ini" -Encoding Default | Select-String -Pattern "^\s*Default\s*=\s*.+" | ConvertFrom-StringData).Default
$ProfileName = Split-Path -Path $String -Leaf
if (-not (Test-Path -Path "$env:APPDATA\Mozilla\Firefox\Profiles\$ProfileName\extensions"))
{
New-Item -Path "$env:APPDATA\Mozilla\Firefox\Profiles\$ProfileName\extensions" -ItemType Directory -Force
}
# Copy .xpi extension file to the extensions folder
Copy-Item -Path "$DownloadsFolder\$ApplicationID.xpi" -Destination "$env:APPDATA\Mozilla\Firefox\Profiles\$ProfileName\extensions" -Force
switch ($Hive)
{
"HKCU"
{
if (-not (Test-Path -Path HKCU:\Software\Mozilla\Firefox\Extensions))
{
New-Item -Path HKCU:\Software\Mozilla\Firefox\Extensions -Force
}
New-ItemProperty -Path HKCU:\Software\Mozilla\Firefox\Extensions -Name $ApplicationID -PropertyType String -Value "$DownloadsFolder\$ApplicationID.xpi" -Force
}
"HKLM"
{
if (-not (Test-Path -Path HKLM:\Software\Mozilla\Firefox\Extensions))
{
New-Item -Path HKLM:\Software\Mozilla\Firefox\Extensions -Force
}
New-ItemProperty -Path HKLM:\Software\Mozilla\Firefox\Extensions -Name $ApplicationID -PropertyType String -Value "$DownloadsFolder\$ApplicationID.xpi" -Force
}
}
}
# Open the about:addons page in a new tab to activate all downloaded extensions manually
Start-Process -FilePath "$env:ProgramFiles\Mozilla Firefox\firefox.exe" -ArgumentList "-new-tab about:addons"
}
$Parameters = @{
ExtensionUris = @(
# https://addons.mozilla.org/en-US/firefox/addon/7tv/
# {7ef0f00c-2ebe-4626-8ed7-3185847fcfad}
"https://addons.mozilla.org/firefox/downloads/file/3824865/7tv.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/betterttv/
"https://addons.mozilla.org/firefox/downloads/file/3820799/betterttv.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/clearurls/
# {74145f27-f039-47ce-a470-a662b129930a}
"https://addons.mozilla.org/firefox/downloads/file/3748919/clearurls.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/darkreader/
"https://addons.mozilla.org/firefox/downloads/file/3806938/dark_reader.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/enhancer-for-youtube/
"https://addons.mozilla.org/firefox/downloads/file/3824758/enhancer_for_youtubetm.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/flagfox/
# {1018e4d6-728f-4b20-ad56-37578a4de76b}
"https://addons.mozilla.org/firefox/downloads/file/3817995/flagfox.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/languagetool/
"https://addons.mozilla.org/firefox/downloads/file/3817128/grammatik_und_rechtschreibprufung_languagetool.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/keepassxc-browser/
"https://addons.mozilla.org/firefox/downloads/file/3813940/keepassxc_browser.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/traduzir-paginas-web/
# {036a55b4-5e72-4d05-a06c-cba2dfcc134a}
"https://addons.mozilla.org/firefox/downloads/file/3822990/traduzir_paginas_web.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/
"https://addons.mozilla.org/firefox/downloads/file/3816867/ublock_origin.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/universal-bypass/
# {529b261b-df0b-4e3b-bf42-07b462da0ee8}
"https://addons.mozilla.org/firefox/downloads/file/3815811/universal_bypass.xpi",
# https://addons.mozilla.org/en-US/firefox/addon/video-ad-block-for-twitch/
# {3385c2d8-dcfd-4f92-adb7-5d8429dee164}
"https://addons.mozilla.org/firefox/downloads/file/3821301/video_ad_block_for_twitch.xpi"
)
Hive = "HKCU"
}
Add-FirefoxExtension @Parameters Works perfectly! 😸 |
Beta Was this translation helpful? Give feedback.
-
Hello again, @farag2
I'm trying to add some extensions using the Add-Firefox-Extensions.ps1 and some errors are happening. Could you please help me to make it work?
So I added the following lines at the end of the script:
$Parameters = @{ ExtensionUris = @( # https://addons.mozilla.org/en-US/firefox/addon/7tv/ "https://addons.mozilla.org/firefox/downloads/file/3824865/7tv.xpi", # https://addons.mozilla.org/en-US/firefox/addon/betterttv/ "https://addons.mozilla.org/firefox/downloads/file/3820799/betterttv.xpi", # https://addons.mozilla.org/en-US/firefox/addon/clearurls/ "https://addons.mozilla.org/firefox/downloads/file/3748919/clearurls.xpi", # https://addons.mozilla.org/en-US/firefox/addon/darkreader/ "https://addons.mozilla.org/firefox/downloads/file/3806938/dark_reader.xpi", # https://addons.mozilla.org/en-US/firefox/addon/enhancer-for-youtube/ "https://addons.mozilla.org/firefox/downloads/file/3824758/enhancer_for_youtubetm.xpi", # https://addons.mozilla.org/en-US/firefox/addon/flagfox/ "https://addons.mozilla.org/firefox/downloads/file/3817995/flagfox.xpi", # https://addons.mozilla.org/en-US/firefox/addon/languagetool/ "https://addons.mozilla.org/firefox/downloads/file/3817128/grammatik_und_rechtschreibprufung_languagetool.xpi", # https://addons.mozilla.org/en-US/firefox/addon/keepassxc-browser/ "https://addons.mozilla.org/firefox/downloads/file/3813940/keepassxc_browser.xpi", # https://addons.mozilla.org/en-US/firefox/addon/traduzir-paginas-web/ "https://addons.mozilla.org/firefox/downloads/file/3822990/traduzir_paginas_web.xpi", # https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/ "https://addons.mozilla.org/firefox/downloads/file/3816867/ublock_origin.xpi", # https://addons.mozilla.org/en-US/firefox/addon/universal-bypass/ "https://addons.mozilla.org/firefox/downloads/file/3815811/universal_bypass.xpi", # https://addons.mozilla.org/en-US/firefox/addon/video-ad-block-for-twitch/ "https://addons.mozilla.org/firefox/downloads/file/3821301/video_ad_block_for_twitch.xpi" ) Hive = "HKCU" } Add-FirefoxExtension @Parameters
I'm having these errors on PowerShell:
VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3824865/7tv.xpi with 0-byte payload
VERBOSE: received 917256-byte response of content type application/x-xpinstall
New-ItemProperty : Cannot bind argument to parameter 'Name' because it is null. At D:\Programs\Scripts\farag2\Mozilla Firefox\3-Add-Firefox-Extensions.ps1:145 char:76 + ... KCU:\Software\Mozilla\Firefox\Extensions -Name $ApplicationID -Proper ... + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [New-ItemProperty], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.NewItemProp
ertyCommand
VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3820799/betterttv.xpi with 0-byte payload
VERBOSE: received 463396-byte response of content type application/x-xpinstall
[email protected] : C:\Users\xxx\Downloads\[email protected] PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox\Extensions PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox PSChildName : Extensions PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3748919/clearurls.xpi with 0-byte payload
VERBOSE: received 832521-byte response of content type application/x-xpinstall
Rename-Item : Cannot create a file when that file already exists.
At D:\Programs\Scripts\farag2\Mozilla Firefox\3-Add-Firefox-Extensions.ps1:123 char:57
At D:\Programs\Scripts\farag2\Mozilla Firefox\3-Add-Firefox-Extensions.ps1:145 char:76
ertyCommand
VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3806938/dark_reader.xpi with 0-byte payload VERBOSE: received 541270-byte response of content type application/x-xpinstall [email protected] : C:\Users\xxx\Downloads\[email protected] PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox\Extensions
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox
PSChildName : Extensions
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3824758/enhancer_for_youtubetm.xpi with 0-byte payload VERBOSE: received 459749-byte response of content type application/x-xpinstall [email protected] : C:\Users\xxx\Downloads\[email protected]. org.xpi PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla
\Firefox\Extensions
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla
\Firefox
PSChildName : Extensions
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3817995/flagfox.xpi with 0-byte payload VERBOSE: received 907340-byte response of content type application/x-xpinstall {1018e4d6-728f-4b20-ad56-37578a4de76b} : C:\Users\xxx\Downloads{1018e4d6-728f-4b20-ad56-37578a4de76b}.xpi
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox
\Extensions
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox
PSChildName : Extensions
PSDrive : HKCU PSProvider : Microsoft.PowerShell.Core\Registry VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3817128/grammatik_und_rechtschreibprufung_languagetool.xpi with
0-byte payload
VERBOSE: received 9489079-byte response of content type application/x-xpinstall
[email protected] : C:\Users\xxx\Downloads\[email protected]
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Fir
efox\Extensions
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Fir
efox
PSChildName : Extensions
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3813940/keepassxc_browser.xpi with 0-byte payload
VERBOSE: received 733778-byte response of content type application/x-xpinstall
[email protected] : C:\Users\xxx\Downloads\[email protected] PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox\Extens ions PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox PSChildName : Extensions
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3822990/traduzir_paginas_web.xpi with 0-byte payload
VERBOSE: received 256042-byte response of content type application/x-xpinstall
{036a55b4-5e72-4d05-a06c-cba2dfcc134a} : C:\Users\xxx\Downloads{036a55b4-5e72-4d05-a06c-cba2dfcc134a}.xpi
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox
\Extensions
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox
PSChildName : Extensions
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3816867/ublock_origin.xpi with 0-byte payload
VERBOSE: received 2834032-byte response of content type application/x-xpinstall
[email protected] : C:\Users\xxx\Downloads\[email protected]
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox\Extensions
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox
PSChildName : Extensions
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3815811/universal_bypass.xpi with 0-byte payload
VERBOSE: received 436472-byte response of content type application/x-xpinstall
Rename-Item : Cannot create a file when that file already exists.
At D:\Programs\Scripts\farag2\Mozilla Firefox\3-Add-Firefox-Extensions.ps1:123 char:57
New-ItemProperty : Cannot bind argument to parameter 'Name' because it is null.
At D:\Programs\Scripts\farag2\Mozilla Firefox\3-Add-Firefox-Extensions.ps1:145 char:76
ertyCommand
VERBOSE: GET https://addons.mozilla.org/firefox/downloads/file/3821301/video_ad_block_for_twitch.xpi with 0-byte
payload
VERBOSE: received 102068-byte response of content type application/x-xpinstall
{3385c2d8-dcfd-4f92-adb7-5d8429dee164} : C:\Users\xxx\Downloads{3385c2d8-dcfd-4f92-adb7-5d8429dee164}.xpi
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox
\Extensions
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Mozilla\Firefox
PSChildName : Extensions
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
PS C:\Windows\system32>
The extensions with errors are not being installed. Am I doing something wrong?
Also, Configure-Firefox.ps1 opens some extension pages already included in Add-Firefox-Extensions.ps1.
I really enjoy the scripts.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions