Functions/GenXdev.Webbrowser.Playwright/Resume-WebbrowserTabVideo.ps1
<##############################################################################
Part of PowerShell module : GenXdev.Webbrowser.Playwright Original cmdlet filename : Resume-WebbrowserTabVideo.ps1 Original author : René Vaessen / GenXdev Version : 1.268.2025 ################################################################################ MIT License Copyright 2021-2025 GenXdev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ################################################################################> ############################################################################### <# .SYNOPSIS Resumes video playback in a YouTube browser tab. .DESCRIPTION Finds the active YouTube browser tab and resumes video playback by executing the play() method on any video elements found in the page. If no YouTube tab is found, the function throws an error. This function is particularly useful for automating video playback control in browser sessions. .EXAMPLE Resume-WebbrowserTabVideo .EXAMPLE wbvideoplay .NOTES Requires an active Chrome browser session with at least one YouTube tab open. The function will throw an error if no YouTube tab is found. ###############################################################################> function Resume-WebbrowserTabVideo { [CmdletBinding()] [Alias('wbvideoplay')] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')] param ( ######################################################################## ) begin { # search for a youtube tab in the current browser session Microsoft.PowerShell.Utility\Write-Verbose 'Attempting to locate an active YouTube tab...' $null = GenXdev.Webbrowser\Select-WebbrowserTab -Name '*youtube*' } process { # verify that a youtube tab was successfully found and selected if ($null -eq $Global:chromeSession) { throw 'No YouTube tab found in current browser session' } Microsoft.PowerShell.Utility\Write-Verbose 'YouTube tab found - initiating video playback...' # execute the play() method on all video elements in the current page $null = GenXdev.Webbrowser\Get-WebbrowserTabDomNodes 'video' 'e.play()' Microsoft.PowerShell.Utility\Write-Verbose 'Video playback successfully resumed' } end { } } |