Page 1 of 2

[solved] How to send Chrome a refresh periodically

Posted: Sat Dec 09, 2023 6:20 pm
by netmaestro
I have a sales page which is always up during the day and it's displayed in Chrome. When sales are recorded on site the info isn't pushed, I have to refresh the page if I want to see the latest sales. I would like to write a small tool in PB that knows where the Chrome window is and refreshes it once per minute. My problem: no idea how to do that. Any suggestions would be much appreciated, thanks.

An alternative would be the webgadget I guess but the doc for it says it uses Internet Explorer 4. IE4 is 26 years old! Can this be right? If so, is it possible to hook it up to a more modern engine?

Re: How to send Chrome a refresh periodically

Posted: Sat Dec 09, 2023 7:36 pm
by Fred
6.10 will ship with edge gadget, won't be long before be available for testing 8)

Re: How to send Chrome a refresh periodically

Posted: Sat Dec 09, 2023 7:41 pm
by netmaestro
Thanks Fred. IE4 is older than PureBasic! Don't tell anyone else, this'll be our secret, OK?

Re: How to send Chrome a refresh periodically

Posted: Sat Dec 09, 2023 7:44 pm
by Kiffi
You can place your page in an iFrame and then update it regularly:

Code: Select all

<html>

<body>

<iframe id="myFrame" src="https://yourSite"></iframe>

<script>
	window.setInterval("reloadIFrame();", 30000);
	function reloadIFrame() {
		document.getElementById("myFrame").src="https://yourSite";
	}
</script>

</body>

</html>

Re: How to send Chrome a refresh periodically

Posted: Sat Dec 09, 2023 8:15 pm
by plouf

Re: How to send Chrome a refresh periodically

Posted: Sun Dec 10, 2023 12:12 am
by BarryG
Fred wrote: Sat Dec 09, 2023 7:36 pm6.10 will ship with edge gadget, won't be long before be available for testing 8)
Wow! This is great news!

Re: How to send Chrome a refresh periodically

Posted: Sun Dec 10, 2023 9:59 am
by Fred
netmaestro wrote: Sat Dec 09, 2023 7:41 pm Thanks Fred. IE4 is older than PureBasic! Don't tell anyone else, this'll be our secret, OK?
Actually it uses lastest IE installed (mostly IE6) :)

Re: How to send Chrome a refresh periodically

Posted: Sun Dec 10, 2023 6:14 pm
by normeus
This code from Rashad might help:

https://www.purebasic.fr/english/viewto ... 61#p611861

I haven't tried it, but KCC was very happy it worked so I assume it works.

Norm

Re: How to send Chrome a refresh periodically

Posted: Sun Dec 10, 2023 7:55 pm
by 6theo4
this works for me

Code: Select all

Procedure SendF5(window$) ; use part of window name  
  r=GetWindow_(GetDesktopWindow_(),#GW_CHILD)
  Repeat
    t$=Space(999) : GetWindowText_(r,@t$,999) 
;        Debug t$  ;to get window titles
  If FindString(LCase(t$), LCase(window$),1)<>0 And IsWindowVisible_(r)=#True
    t$=Trim(t$)
;    If t$ = window$ And IsWindowVisible_(r)=#True   ; use this part for full window name 
    w=r
    Else
      r=GetWindow_(r,#GW_HWNDNEXT)
    EndIf
  Until r=0 Or w<>0  
 handle = w     
  If IsWindow_(handle)=0 ; Does the target window actually exist?
    ProcedureReturn 0 ; Nope, so report 0 for failure to type.
  Else
    ; This block gives the target window the focus before typing.
    thread1=GetWindowThreadProcessId_(GetForegroundWindow_(),0)
    thread2=GetWindowThreadProcessId_(handle,0)
    If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#True) : EndIf
    SetForegroundWindow_(handle) ; Target window now has the focus for typing.
    Sleep_(125) ; 1/8 second pause before typing to prevent fast CPU problems.
    ; Now the actual typing starts.
    keybd_event_(#VK_F5,0,0,0)    
    If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#False) : EndIf ; Finished typing to target window!
    ProcedureReturn 1 ; Report successful typing!  :)
  EndIf
EndProcedure

Debug SendF5("window title")

Re: How to send Chrome a refresh periodically

Posted: Sun Dec 10, 2023 9:50 pm
by netmaestro
Thanks, 6theo4, that works perfectly for me! Thanks as well to all who gave ideas, it's much appreciated :mrgreen:

Re: How to send Chrome a refresh periodically

Posted: Sun Dec 10, 2023 10:08 pm
by BarryG
normeus wrote: Sun Dec 10, 2023 6:14 pmKCC was very happy it worked so I assume it works
You only need to see an animated GIF from KCC to know some code worked. :lol:

Re: [solved] How to send Chrome a refresh periodically

Posted: Sun Dec 10, 2023 11:07 pm
by netmaestro
Ok, so this is just weird now. The code from 6theo4 works perfectly, refreshing my window at the selected intervals. But only if run from the IDE. If I compile the code, add it to my taskbar and run it from there it does not work anymore. Anyone have an idea?

Re: [solved] How to send Chrome a refresh periodically

Posted: Sun Dec 10, 2023 11:25 pm
by 6theo4
maybe forgot to remove the "Debug" ?

Re: [solved] How to send Chrome a refresh periodically

Posted: Mon Dec 11, 2023 12:30 am
by skywalk
Yeah, the iFrame html approach did not work for me.
And sendkeys will probably get blocked in the future.

Re: [solved] How to send Chrome a refresh periodically

Posted: Mon Dec 11, 2023 1:22 am
by Kiffi
skywalk wrote: Mon Dec 11, 2023 12:30 amYeah, the iFrame html approach did not work for me.
Which browser?