West Wind Internet and Client Tools
Opening local HTML file on same browser tab
Gravatar is a globally recognized avatar based on your email address. Opening local HTML file on same browser tab
  Aldrin Austria
  All
  Jul 5, 2022 @ 11:02am

Using ShellExecute is it possible to open a local HTML file on the same browser on each call? The HTML file is basically a harness where information is prepopulated from VFP with a submit button. On the onSubmit call in this HTML file, the result is returned into the same browser tab (instead of target="_blank").

What I wanted to achieve is on the next if the browser is still opened on the initial ShellExecute call from my VFP app, the next ShellExecute call should open the local HTML file on the same browser tab. Is this possible?

Gravatar is a globally recognized avatar based on your email address. re: Opening local HTML file on same browser tab
  Rick Strahl
  Aldrin Austria
  Jul 5, 2022 @ 04:29pm

Not possible... There's no control support for the ShellExecute() API. It's simply a file->application mapping. The application determines how to open the file.

I don't even think that the Chromium command line options allow for this even if you were to explicitly launch a browser instance (messy, but doable).

If you really need to do this I'd recommend embedding a browser window into your own app and showing the content there.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Opening local HTML file on same browser tab
  Aldrin Austria
  Rick Strahl
  Jul 6, 2022 @ 07:23am

Got it. With regards to embedding the browser, I thought this is only possible on IE? The issue with this if my assumption for IE is true is my requirement only allows Chrome, Chromium(Edge) or Safari browser. Is it possible to embed one of these?

Gravatar is a globally recognized avatar based on your email address. re: Opening local HTML file on same browser tab
  Rick Strahl
  Aldrin Austria
  Jul 6, 2022 @ 04:52pm

Yeah embedding only works with IE, but I guess it depends what your are displaying and from where. IE is decent with basic HTML 5, but it depends. It's getting harder and harder to ensure that stuff renders there but if it's HTML you control you can taylor it so it works.

For example, Help Builder uses the IE control and it creates fairly rich HTML5 content. But I control it so I can make sure it uses what works.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Opening local HTML file on same browser tab
  Aldrin Austria
  Rick Strahl
  Jul 7, 2022 @ 08:19am

Unfortunately, I cannot use IE anymore for this project. One of the strict requirements for browser compatibility are only Chrome, Chromium (Edge) or Safari.

Thank you.

Gravatar is a globally recognized avatar based on your email address. re: Opening local HTML file on same browser tab
  Rick Strahl
  Aldrin Austria
  Jul 7, 2022 @ 10:58am

Here's another idea:

Build a small .NET Executable and embed the WebView2 control (which uses the Edge Chromium Runtime). You can then automate the EXE either by launching it, or by building some two-way communication into it to ensure you only have one instance running. You could also automate a .NET assembly with wwDotnetBridge in the same way, but there are some issues to work around for managing the .NET Event loop from a FoxPro application.

Either way - this allows you to control how the content is displayed.

To be honest though I don't think this is worth it just to be able to get the same window to show. Unless you plan on showing lots of content externally like this opening multiple tabs shouldn't be a huge burden and it has the advantage that users get to use the browser they normally use.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Opening local HTML file on same browser tab
  Aldrin Austria
  Rick Strahl
  Jul 7, 2022 @ 12:57pm

Interesting approach. I will dig into that suggestion.

One question though, using WW Internet and Client tools can I do the following:

  • Button in my VFP app where I have the username/password
  • Call wwHTTP::Post with the credentials above
  • Launch default browser where it would show whatever default page is after authentication.

Here's a simple code that I tried, but it seems it is creating a file and loading that file into the browser. What I would like to achieve is to open up the browser but on this particular URL https://thewebsite.ca but the credentials has validated already based on the cData content.

#INCLUDE wconnect.h
SET PROCEDURE TO "wwUtils.prg" ADDITIVE
SET PROCEDURE TO "wwAPI.prg"ADDITIVE
SET PROCEDURE TO "wwHTTP.prg"  ADDITIVE

LOCAL loHttp as wwHttp OF wwhttp.prg
loHttp=CREATEOBJECT("wwHTTP")
TEXT TO cData NOSHOW 
server=https://thewebsite.ca/launch&username=aldrin&password=mypwd&domain=xx.yyyy.zz.ca
ENDTEXT 
loHttp.cContentType="application/x-www-form-urlencoded"
lcHTML = loHttp.Post("https://thewebsite.ca/launch",m.cData)
ShowHTML( m.theresponseURL )
Gravatar is a globally recognized avatar based on your email address. re: Opening local HTML file on same browser tab
  Rick Strahl
  Aldrin Austria
  Jul 7, 2022 @ 01:10pm

Not quite sure what you're asking, but if you want to authenticate with wwHttp and then open a browser and expect it to be logged in, no there's no way that can work as the wwHttp session and the actual browser session don't share the same browser environment.

It might be possible do this via automation if you use the seperate .NET application with WebView approach as you could pass in the url, authentication and then open the appropriate page.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Opening local HTML file on same browser tab
  Aldrin Austria
  Rick Strahl
  Jul 7, 2022 @ 01:17pm

Your on-point on what I wanted to achieve.

Currently, what I'm doing is to create a dummy.html created in VFP (via that button call) with all the credential on it. The dummy.html is being loaded via ShellExec. The content of this dummy.html has a Submit button where I can trigger onload

onload="setTimeout(function() { document.getElementById('cmdSubmit').click() }, 200)"

This is working but can pose a security issue since I'm creating that dummy file. I can delete it with no issue after the submit, but I have to do a lot of convincing.

One thing that they told me is if I can use a socket.. something like this (https://docs.microsoft.com/en-us/dotnet/api/system.net.security.sslstream?view=net-6.0)

Gravatar is a globally recognized avatar based on your email address. re: Opening local HTML file on same browser tab
  Rick Strahl
  Aldrin Austria
  Jul 7, 2022 @ 02:42pm

If you control the page that you're rendering, you can use WebSockets to communicate with your app. I do this in Web Connection for the LiveReload functionality where the FoxPro app sends a Web Socket request to the Web page to cause the page to refresh after code's been recompiled and the server has restarted.

The client page can then include the JS WebSocket client (part of the DOM APIs) to receive messages and do as you need to. I don't think you can load a different page and push POST data into it though as that requires navigating off, or if you use iframe has security issues.

Once you have the socket connection, you can send messages back and forth. .NET has a client Web Socket implementation that's relatively easy to use.

+++ Rick ---

© 1996-2022