Re: Reload Browser Tab on Windows
by Corion (Patriarch) on Dec 21, 2020 at 20:57 UTC
|
It's easy to automate in two ways:
The cross-browser way would be to serve the HTML through a local webserver and inject a small websocket script into it that calls back to the server and leans when the HTML or CSS get changed. See Mojolicious::Plugin::AutoReload or my App::Mojo::AssetReloader.
The Chromium/Chrome/Edge-only way would be with WWW::Mechanize::Chrome and Filesys::Notify::Simple, reloading the page whenever it needs to be reloaded. This has the slim advantage of not modifying the HTML page.
| [reply] |
|
|
yeah, sure. I also hacked a JS-snippet 15+ years ago that did a reload based on the change time of a local file. :)
But a little help with Win32::OLE would be nice. I'm also interested to move windows to have my IDE and Browsers side by side, depending on screen resolution.
Though looks like I can do it with powershell.
| [reply] |
|
|
$mech->target->send_message('Browser.setWindowBounds',
windowId => $window_info->{windowId},
bounds => {
'height' => 1600,
'top' => 0,
'width' => 2560,
'left' => 0,
},
)->get;
| [reply] [d/l] |
|
|
Re: Reload Browser Tab on Windows
by pryrt (Abbot) on Dec 21, 2020 at 21:31 UTC
|
Instead of Win32::OLE, have you considered Win32::GuiTest -- it is a module specifically designed for remote-running Windows apps: clicking buttons, activating menus, typing keys.
Otherwise, taking a look at the code from the first answer to the SO post you linked,
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate("Firefox")
WshShell.SendKeys "{F5}"
WshShell.AppActivate("TextPad")
I think that the CreateObject would be equivalent to the Win32::OLE->new('WScript.Shell'), and that the methods should translate across... but I haven't tried.
I'll try:
perl -MWin32::OLE -e "$obj = Win32::OLE->new('WScript.Shell') or die $
+!; $obj->AppActivate('Chrome') or die $!; $obj->SendKeys('{F5}');"
Yep, that refreshed the current page in Chrome for me.
Hopefully, that gives you enough to get started with. | [reply] [d/l] [select] |
|
|
Since I recommended Win32::GuiTest, I should have given equivalent example using that module, too:
C:\usr\local\share>perl -MWin32::GuiTest=":FUNC" -le "my ($chrome) = F
+indWindowLike(0, 'Google Chrome$'); print $chrome; print GetWindowTex
+t($chrome); SetForegroundWindow($chrome);SendKeys('{F5}')"
That also refreshes the current Chrome window for me. | [reply] [d/l] |
|
|
> Instead of Win32::OLE, have you considered Win32::GuiTest -- it is a module specifically designed for remote-running Windows apps: clicking buttons, activating menus, typing keys.
Many thanks, I forgot about it, especially FindWindowLike will help me identifying the right instance of FF.
:)
> Otherwise, taking a look at the code from the first answer to the SO post you linked,
I have to admit, that's what I'm using meanwhile via Powershell.
Less dependencies! :)
| [reply] [d/l] |
Re: Reload Browser Tab on Windows
by haukex (Archbishop) on Dec 21, 2020 at 20:55 UTC
|
| [reply] [d/l] |
|
|
| [reply] |
|
|
Sorry Script= Perl Program
This is not JS-Monks after all! ;-)
Sure, I just thought you might be playing with WebPerl ;-) I'm a little unclear on your architecture: would I be correct in guessing that you've got a Perl script that's generating static HTML, and that's why you want to reload the browser from the Perl script instead of from inside the HTML? (And even if that's the case, why not just whip up a quick server that serves the HTML on a local address? That way you could solve this using JS / Websockets / etc.)
| [reply] |
|
|
|
|
|