[solved] How to send Chrome a refresh periodically

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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

Post by netmaestro »

I've been trying the iFrame approach by Kiffi but without success. I slightly modified the code to make sure it's using html5 and edited the address to reflect my page but with both Chrome and Edge this is my result:
Image
And here is the code I used:
<!doctype html>
<html>

<head>
<meta charset="utf-8">
</head>

<body>

<iframe id="myFrame" src="https://www.squareup.com/ca/en"></iframe>

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

</body>

</html>
BERESHEIT
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

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

Post by firace »

netmaestro wrote: Sun Dec 10, 2023 11:07 pm 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?
In the compiled version did you remove the Debug statement?

Code: Select all

Debug SendF5("window title")
should be

Code: Select all

SendF5("window title")
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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

Post by netmaestro »

Thanks 6theo4 and firace, that was it. I took the Debug statement out quite a while back and I thought I'd recompiled after that but I hadn't. Working perfectly now. Kiffi's code should work too imho but the server refuses to connect in both Chrome and Edge.
BERESHEIT
6theo4
New User
New User
Posts: 8
Joined: Sun Dec 08, 2013 8:44 pm

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

Post by 6theo4 »

you should add an entry with the chrome title when your connection is interrupted so you can also get a refresh after a disconnection.... :D
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

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

Post by BarryG »

netmaestro wrote: Sat Dec 09, 2023 6:20 pmWhen sales are recorded on site the info isn't pushed, I have to refresh the page if I want to see the latest sales.
You should be able to use ReceiveHTTPMemory() to get the page's raw HTML periodically, and then parse that. I do it all the time to get info from my website. No need to muck around with a Chrome window and F5.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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

Post by netmaestro »

@BarryG, that's a great idea and I'll see if the site will talk to my computer. But it's a banking site so its security may not be something I can get through to. With the webpage I log in with my credentials and it sometimes gives me captchas and text messages containing 6 digit codes. I don't think my chances are going to be that good.
BERESHEIT
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

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

Post by skywalk »

Kiffi wrote: Mon Dec 11, 2023 1:22 am
skywalk wrote: Mon Dec 11, 2023 12:30 amYeah, the iFrame html approach did not work for me.
Which browser?
Chrome and Edge are based on chromium code. Both bowsers fail to connect certain websites. Dell.com connects but I did not inspect why the others fail.

Code: Select all

<html>
<body>
<!--
<iframe id="myFrame" src="https://www.dell.com"></iframe>
-->
<iframe id="myFrame" src="https://www.ibm.com/us-en"></iframe>
<script>
	window.setInterval("reloadIFrame();", 30000);
	function reloadIFrame() {
<!--
		document.getElementById("myFrame").src="https://www.dell.com";
-->
		document.getElementById("myFrame").src="https://www.ibm.com/us-en";
	}
</script>
</body>
</html>
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

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

Post by BarryG »

That certainly changes things, NetMaestro, when a login and captchas are involved.
infratec
Always Here
Always Here
Posts: 7583
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

Without keyboard hacking involved:

Code: Select all

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  WebGadget(0, 10, 10, 580, 280, "https://www.purebasic.com") 
  AddWindowTimer(0, 123, 3000)
  Repeat 
    Event = WaitWindowEvent()
    If Event = #PB_Event_Timer
      If EventTimer() = 123
        SetGadgetItemText(0, #PB_Web_HtmlCode, "<script>document.location.replace(location.href);</script>")
      EndIf
    EndIf
  Until Event = #PB_Event_CloseWindow 
EndIf
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

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

Post by Kiffi »

Some website operators prevent their site from running in an IFrame. For this reason, my solution does not work.

+1 for infratec's solution.
Hygge
infratec
Always Here
Always Here
Posts: 7583
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

There are different methods available to do it with javascript.
You can read about the cons and pros here:
https://www.freecodecamp.org/news/javas ... age-in-js/
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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

Post by netmaestro »

Thanks infratec but the site won't work in the native webgadget. But the WebGadgetEx by RSBasic works flawlessly. So I have a couple of solutions that are working now until Fred releases b1 of PB 6.10. Then the native webgadget should do the trick and your code will be the best and simplest solution overall. You're just a couple weeks early is all. I found your implementation of js very instructive as I'm pretty much of a noob when it comes to javascript.
BERESHEIT
infratec
Always Here
Always Here
Posts: 7583
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

There is also an other possibility: use the WebView2 runtime from Windows Edge

https://www.purebasic.fr/english/viewto ... 39#p609539

This implements a full working WebView2Gadget().
Post Reply