Functions/GenXdev.Webbrowser/Open-WebbrowserSideBySide.ps1
|
#################################################################### <# .SYNOPSIS Launches a new web browser window with specific positioning. .DESCRIPTION Opens a new browser window (Edge or Chrome) positioned on the right side of the primary monitor in background mode. .LICENSE Copyright (C) 2026 René Vaessen / GenXdev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. .PARAMETER Edge Opens Microsoft Edge browser instead of the default browser. .PARAMETER Chrome Opens Google Chrome browser instead of the default browser. .EXAMPLE wbn -Edge .EXAMPLE wbn -ch #> function Open-WebbrowserSideBySide { [CmdletBinding()] [Alias("wbn")] param( ####################################################################### [Parameter( Mandatory = $false, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $false, HelpMessage = 'The URLs to open in the browser' )] [Alias('Value', 'Uri', 'FullName', 'Website', 'WebsiteUrl')] [string[]] $Url, ####################################################################### [Parameter( Mandatory = $false, Position = 1, HelpMessage = ('The monitor to use, 0 = default, -1 is discard, ' + '-2 = Configured secondary monitor, defaults to ' + "`$Global:DefaultSecondaryMonitor or 2 if not found") )] [Alias('m', 'mon')] [int] $Monitor = -2, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'The initial width of the webbrowser window' )] [int] $Width = -1, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'The initial height of the webbrowser window' )] [int] $Height = -1, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'The initial X position of the webbrowser window' )] [int] $X = -999999, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'The initial Y position of the webbrowser window' )] [int] $Y = -999999, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Set the browser accept-lang http header' )] [Alias('lang', 'locale')] [string] $AcceptLang = $null, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Force enable debugging port, stopping existing ' + 'browsers if needed') )] [switch] $Force, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Opens in Microsoft Edge' )] [Alias('e')] [switch] $Edge, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Opens in Google Chrome' )] [Alias('ch')] [switch] $Chrome, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Opens in Microsoft Edge or Google Chrome, ' + 'depending on what the default browser is') )] [Alias('c')] [switch] $Chromium, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Opens in Firefox' )] [Alias('ff')] [switch] $Firefox, ############################################################################### [Alias('pw')] [Parameter( Mandatory = $false, HelpMessage = ('Use Playwright-managed browser instead of the ' + 'OS-installed browser') )] [switch] $PlayWright, ############################################################################### [Alias('wk')] [Parameter( Mandatory = $false, HelpMessage = ('Opens the Playwright-managed WebKit browser. ' + 'Implies -PlayWright') )] [switch] $Webkit, ######################################################################## [Parameter( Mandatory = $false, HelpMessage = 'Run the browser without a visible window' )] [Alias('hl')] [switch] $Headless, ############################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Place browser window on the left side of the screen' )] [switch] $Left, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Place browser window on the right side of the screen' )] [switch] $Right, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Place browser window on the top side of the screen' )] [switch] $Top, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Place browser window on the bottom side of the screen' )] [switch] $Bottom, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Place browser window in the center of the screen' )] [switch] $Centered, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Opens in fullscreen mode' )] [Alias('fs', 'f')] [switch] $FullScreen, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Opens in incognito/private browsing mode' )] [Alias('incognito', 'inprivate')] [switch] $Private, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Hide the browser controls' )] [Alias('a', 'app', 'appmode')] [switch] $ApplicationMode, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Prevent loading of browser extensions' )] [Alias('de', 'ne', 'NoExtensions')] [switch] $NoBrowserExtensions, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Disable the popup blocker' )] [Alias('allowpopups')] [switch] $DisablePopupBlocker, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ("Don't re-use existing browser window, instead, " + 'create a new one') )] [Alias('nw', 'new')] [switch] $NewWindow, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Focus the browser window after opening' )] [Alias('fw', 'focus')] [switch] $FocusWindow, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Set the browser window to foreground after opening' )] [Alias('fg')] [switch] $SetForeground, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Maximize the window after positioning' )] [switch] $Maximize, ######################################################################## [Parameter( Mandatory = $false, HelpMessage = 'Restore the window to normal state after positioning' )] [switch] $SetRestored, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Returns a PowerShell object of ' + 'the browserprocess') )] [Alias('pt')] [switch]$PassThru, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Removes the borders of the window' )] [Alias('nb')] [switch] $NoBorders, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = 'Restore PowerShell window focus' )] [Alias('rf', 'bg')] [switch] $RestoreFocus, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Position browser window either fullscreen on ' + 'different monitor than PowerShell, or side by side with ' + 'PowerShell on the same monitor') )] [Alias('sbs')] [switch] $SideBySide, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Keystrokes to send to the Window, ' + 'see documentation for cmdlet GenXdev\Send-Key') )] [string[]] $KeysToSend, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Escape control characters and modifiers when ' + 'sending keys') )] [Alias('Escape')] [switch] $SendKeyEscape, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Hold keyboard focus on target window when ' + 'sending keys') )] [Alias('HoldKeyboardFocus')] [switch] $SendKeyHoldKeyboardFocus, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Use Shift+Enter instead of Enter when ' + 'sending keys') )] [Alias('UseShiftEnter')] [switch] $SendKeyUseShiftEnter, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Delay between different input strings in ' + 'milliseconds when sending keys') )] [Alias('DelayMilliSeconds')] [int] $SendKeyDelayMilliSeconds, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Use alternative settings stored in session for ' + 'preferences') )] [switch] $SessionOnly, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Clear alternative settings stored in session for ' + 'AI preferences') )] [switch] $ClearSession, ####################################################################### [Parameter( Mandatory = $false, HelpMessage = ('Store settings only in persistent preferences ' + 'without affecting session') )] [Alias('FromPreferences')] [switch] $SkipSession ####################################################################### ) begin { Microsoft.PowerShell.Utility\Write-Verbose 'Launching new browser window' } process { GenXdev\Set-WindowPosition -Left -Monitor 0 $NewWindow = $true $Monitor = 0 $SideBySide = $true; $RestoreFocus = $true $params = GenXdev\Copy-IdenticalParamValues ` -BoundParameters $PSBoundParameters ` -FunctionName "GenXdev\Open-Webbrowser" ` -DefaultValues (Microsoft.PowerShell.Utility\Get-Variable -Scope Local -ErrorAction SilentlyContinue) GenXdev\Open-Webbrowser @params } end { Microsoft.PowerShell.Utility\Write-Verbose 'Browser window launched successfully' if ($Force) { $params = GenXdev\Copy-IdenticalParamValues ` -BoundParameters $PSBoundParameters ` -FunctionName "GenXdev\Select-WebbrowserTab" ` -DefaultValues (Microsoft.PowerShell.Utility\Get-Variable -Scope Local -ErrorAction SilentlyContinue) GenXdev\Select-WebbrowserTab @params } } } |