Launching Chrome with .bat file with specific scroll-down - google-chrome

This is a follow-up question to Launching 2 Google Chrome windows in different positions and Launch Google Chrome from the command line with specific window coordinates.
Apart from what has already been said in those 2 posts, I am wondering if there is a command I can add to a batch file which allows me to open a new Chrome window scrolled down to a specific position, or by a specific "amount".
I have checked this page and this page but have not found anything.

Here I use sendkeys after opening chrome to open the console, focus on the console, and input some javascript to scroll 100px down.
#if (#CodeSection == #Batch) #then
#echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
rem Start the other program in the same Window
call "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.send?view=netframework-4.8
timeout /t 2
%SendKeys% "^(+({J}))"
timeout /t 2
%SendKeys% "^(`)"
%SendKeys% "window.scrollBy{(}0, 100{)};~"
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

Related

Chrome Extension Install via Command Line

i made a zip file containing a google chrome extension pack and made it "public" via a download link (lets say its http://someaddress.com/extension.zip).
Then, i looked a lot on stackoverflow and found multiple approaches to add this extension as "automatically" as possible (without publishing it on the google store).
I came up with this BATCH file:
#echo off
setlocal
cd /d %~dp0
set dwURI="http://someaddress.com/extension.zip"
set tpZIP="%temp%\extension.zip"
call :DownloadFile %dwURI% %tpZIP%
call :UnZipFile "%AppData%" %tpZIP%
del "%temp%\extension.zip"
taskkill /f /im "chrome.exe"
start chrome --load-extension="%AppData%\extension"
start "%AppData%\extension"
exit /b
:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\unzip.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs% echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If Not fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
:DownloadFile <URL> <DownloadTo>
bitsadmin /transfer mydownloadjob /download /priority FOREGROUND %1 %2
cls
To actually "install" the extension the command ended up beeing this one line start chrome --load-extension="%AppData%\extension" that sets the extension unpacked path to load.
My problem: it only loads the extension on that particular call. If i close chrome and open it again it's not there, it doesn't "auto load".
If i go to the appdata folder and install the unpacked extension on google chrome enableing the developer option and seeking that folder it stays "installed".
Is there a "--install-extension:" command on google chrome that i cannot find, or is there another way to order it do install it?

Headless Chrome command line - set timeout

I'm trying to print pdf from Gmail with headless chrome in command line.
I cannot install pupeteer or another tool with the computer that script will run on, due to unability to install anything.
For simple gsuite pages such as https://myaccount.google.com/, my script runs perfectly.
For more complex ones such as gmail, the output PDF I get shows a partially loaded page:
output PDF
I'm already using the --run-all-compositor-stages-before-draw option which should wait for the page to resolve before printing.
I've tried to add --virtual-time-budget=10000 just before --run-all-compositor-stages-before-draw, however if I ask for more than 2000 milliseconds the command runs for ever without producing the output pdf.
See my code so far below (which I put in a .bat file)
Does anyone have encountered that issue ? Any lead on how to solve it ? Any ways to first load the page, then have a timeout command, then print to pdf ?
I couldn't find a solution so far on the web.
Thanks :)
Ps: english isn't my primary language, please excuse any mistake
#set outputFile=C:\Users\MyUserName\Temp\testPDFprintChromeheadless\test.pdf
#set chromeDirectory=C:\Program Files (x86)\Google\Chrome\Application
#set url=https://mail.google.com/mail/
#set userData=C:\Users\MyUserName\AppData\Local\Google\Chrome\User Data
#set profile=MyChromeProfile
#set useragentChrome="Mozilla/5.0 (X11\\; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36"
#cd "%chromeDirectory%"
chrome.exe --headless --disable-gpu --profile-directory="%profile%" --user-data-dir="%userData%" --user-agent=%useragentChrome% --run-all-compositor-stages-before-draw --print-to-pdf="%outputFile%" --print-to-pdf-no-header "%url%"
pause
Edit :
Here are the logs I get.
AccÞs refusÚ means Accès refusé which is french for Access denied.
I don't have administrator rights on this computer, thus not able to write within the Chrome directory, that could explain this access denied.
[0820/101506.995:ERROR:cache_util_win.cc(20)] Unable to move the cache: AccÞs refusÚ. (0x5)
[0820/101506.996:ERROR:cache_util.cc(144)] Unable to move cache folder C:\Users\MyUserName\AppData\Local\Google\Chrome\User Data\Default\GPUCache to C:\Users\MyUserName\AppData\Local\Google\Chrome\User Data\Default\old_GPUCache_000
[0820/101506.997:ERROR:disk_cache.cc(184)] Unable to create cache
[0820/101506.997:ERROR:shader_disk_cache.cc(606)] Shader Cache Creation failed: -2
[0820/101509.033:ERROR:cache_util_win.cc(20)] Unable to move the cache: AccÞs refusÚ. (0x5)
[0820/101509.034:ERROR:cache_util.cc(144)] Unable to move cache folder C:\Users\MyUserName\AppData\Local\Google\Chrome\User Data\Default\Cache to C:\Users\MyUserName\AppData\Local\Google\Chrome\User Data\Default\old_Cache_000
[0820/101509.035:ERROR:disk_cache.cc(184)] Unable to create cache
[0820/101510.020:ERROR:service_worker_storage.cc(1899)] Failed to delete the database: Database IO error
[0820/101513.168:INFO:CONSOLE(1763)] "Deprecated API for given entry type.", source: https://mail.google.com/_/scs/mail-static/_/js/k=gmail.main.fr.YnGL5qwRpj4.O/am=rvxfykdgoP_swM-GUSAcAAM5SAABYIUsYuW09wdKmv8BAwAGoG_F8GAQrnkAdJzCuAQAAAAAAAAAAAAAAAAAAADsAisGAQ/d=1/exm=b/ed=1/im=1/dg=0/br=1/wt=1/rs=AHGWq9AzRZEBJ1Ek7NOabODYvaA7PPmCUQ/cb=loaded_1/m=a (1763)
[0820/101519.465:INFO:headless_shell.cc(648)] Written to file C:\Users\MyUserName\Temp\testPDFprintChromeheadless\test.pdf.

Windows batch start chrome process with defined process ID

I have to start a Web Application with a batch file in the Chrome Browser with a predefined process ID so i can kill that specific Chrome Window later with another batch file. Is there any way to to this?
By typing this command on the CMD console you can see how to create a process :
wmic process call create /?
And this too : How to terminate a Process :
wmic process call terminate /?
So, you can give a try for this batch file :
#echo off
set "targetfile=C:\Program Files\Google\Chrome\Application\chrome.exe"
set targetfile=%targetfile:\=\\%
#for /f "tokens=2 delims==; " %%# in ('wmic PROCESS CALL CREATE "%targetfile%" ^|findstr /I "ProcessId"') do set "PID=%%#"
echo The Process is created with PID=%PID%
pause
wmic process where ProcessId="%PID%" call terminate
REM Taskkill /PID %PID%
pause
And you can create a Subroutine named : :Create_Process <TargetFile> <PID> in order to call it like this :
#echo off
Title Start chrome process with a defined process ID
set "TargetFile=C:\Program Files\Google\Chrome\Application\chrome.exe"
Call :Create_Process "%TargetFile%" PID
echo The Process is created with PID=%PID%
pause
wmic process where ProcessId="%PID%" Call Terminate
REM Taskkill /PID %PID%
pause
Exit
::-----------------------------------------------------------------
:Create_Process <TargetFile> <PID>
Set "TargetFile=%~1"
Set TargetFile=%TargetFile:\=\\%
#for /f "tokens=2 delims==; " %%# in (
'wmic PROCESS CALL CREATE "%TargetFile%" ^|findstr /I "ProcessId"'
) do set "%2=%%#"
Exit /B
::-----------------------------------------------------------------

How do I launch a particular URL the same time daily in Chrome

I want to launch a particular URL in chrome every day at the same time. How can I achieve this using command line?
There are two ways to do this. The first being from a single command line. You will want to create a new task in Task Scheduler and have it run a command at a desired time. If you wish to use a different browser that supports command lines, be sure to use _ for any spaces in the directory path.
Command line:
SchTasks /Create /SC DAILY /TN "New_Task" /TR "start "C:\Program_Files_(x86)\Google\Chrome\Application\chrome.exe" www.stackoverflow.com" /ST 09:00
The second option is to use a batch file you store somewhere and it will be called to using the SchTasks. Simply create the site1.bat and place it somewhere safe example C:\Windows\My Tasks.
From Batch:
#ECHO OFF
#set Task_Name=Task1
#Set Time=09:00
#set Site=www.stackoverflow.com
schtasks /query /TN "%Task_Name%" >NUL 2>&1
IF %ERRORLEVEL% EQU 0 (goto :EXISTS) ELSE (goto :CREATE)
:CREATE
Set Folder=%~dp0
Set Name=%~nx0
Echo Task does not already exist, creating it now.
SchTasks /Create /SC DAILY /TN "%Task_Name%" /TR "%Folder%%Name%" /ST %Time%
goto :eof
:EXISTS
start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %Site%
goto :eof

Running Chrome in kiosk mode not working?

I am trying to run Chrome in "kiosk" mode but for some reason it is not working. I tried all the possible switch combinations and disable running Chrome in backround through GPO but it is not working.
Here is the current link I am running.
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -ignore-certificate-errors --chrome --kisok --fullscreen https://web.page.com
Is there any other setting that I need to check or configure?
Here is also a list of tasks that are running:
**System Idle Process
armsvc.exe
audiodg.exe
cb.exe
CcmExec.exe
cmd.exe
concentr.exe
conhost.exe
csrss.exe
dwm.exe
DWRCS.EXE
DWRCST.EXE
EngineServer.exe
explorer.exe
FrameworkService.exe
igfxCUIService.exe
igfxEM.exe
igfxHK.exe
lsass.exe
lsm.exe
McShield.exe
McTray.exe
mfeann.exe
mfevtps.exe
naPrdMgr.exe
PresentationFontCache.exe
RAVBg64.exe
RAVCpl64.exe
Receiver.exe
redirector.exe
SearchIndexer.exe
SelfServicePlugin.exe
services.exe
shstat.exe
smss.exe
spoolsv.exe
ssonsvr.exe
svchost.exe
System
taskeng.exe
taskhost.exe
TCPSVCS.EXE
UdaterUI.exe
VsTskMgr.exe
wfcrun32.exe
wininit.exe
winlogon.exe
WmiPrvSE.exe
Deni said he was running RSOP and it turned out that the GPO setting for blocking Chrome to run with kiosk mode was not applying. He said he fixed it (I am assuming he used gpupdate /force in Command Prompt to update GPO). He said the parameters that he is using is
--ignore-certificate-errors and --kiosk