PrivateFunctions/Get-Puppeteer_SetChromeBrowserOptions.ps1
<#
.SYNOPSIS This function returns the Node JS Puppeteer code for setting the chrome browser options. #> function Get-Puppeteer_SetChromeBrowserOptions { [CmdletBinding(PositionalBinding=$true)] [OutputType([String])] param ( # Select if the chrome browser is executed as headless (no GUI) [Parameter(Mandatory=$false)] [ValidateNotNull()] [Bool]$isHeadless = $true, # The width of the browser viewport [Parameter(Mandatory=$false)] [ValidateNotNullOrEmpty()] [String]$width = "1920", # The height of the browser viewport [Parameter(Mandatory=$false)] [ValidateNotNullOrEmpty()] [String]$height = "1080" ) # Generate the code $code = @" // Create object to store the Chrome browser options chromeBrowserOptions = {}; // Select whether Chrome will be executed as headless (no GUI) chromeBrowserOptions.headless = %isHeadless%; // Set default viewport to be larger, otherwise some page elements will not be available chromeBrowserOptions.defaultViewport = Object; chromeBrowserOptions.defaultViewport.width = %width%; chromeBrowserOptions.defaultViewport.height = %height%; "@ $code = $code -replace "%isHeadless%", "$($isHeadless)".ToLower() $code = $code -replace "%width%", $width $code = $code -replace "%height%", $height # Return the generated code return $code } |