PDA

View Full Version : Run a synchronous Browser



Kaemo
20th January 2015, 10:38
Hello all,
I have the following problem :
I need to open URLs using a new window of the default browser of the OS. However, the HMI shall inhibit some user actions until the opened browser page is closed.

I tried things but still could not find any good solution :
- openUrl() method perfectly answer to the first part of my problem but it is not synchronous.
- I tried to start the browser using QProcess :
* I did not found a way to acquire the default OS browser at the runtime. Thus, I created a configuration file for my application which contains the exe paths of the browsers for all systems. This solution is good enough for me but I am open to any suggestions...
* I launch the URLs using QProcess::start(). However, I have different behaviors depending on the meteorite falls on Mars :
-> Windows, IExplorer : It seems to behave like I want.
-> Linux/Windows, Firefox : I have to deal with another problem : firefox cannot be easily launch in a new separate process. Thus, if the browser is not initially launched, the solution works. If firefox is already launched, QProcess exit immediately.

I am using Qt5 and my soft is executed on Linux and Windows.

Did anyone face this general problem of launching a synchronous browser?

I am sorry if my english is full of mistakes. I tried my best :)

anda_skoa
20th January 2015, 11:41
I don't think there is any generic solution on the process level since there are way to many browsers with different behaviors.

You could try the -new-instance option for Firefox, but of course that will only work for Firefox.

Can I ask why you need that?
Why is it important that the browser window has been closed?

Cheers,
_

Kaemo
20th January 2015, 13:23
In fact, I missed the '-new-instance' option.
This curious option is not documented (https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options) and it doesn't seems to work... :
- <firefox -new-instance www.google.com> doesn't start a new process; it only launch the URL in a new window. The effect of -new-instance seems to be close to -new-window.
- This option doesn't "freeze" QProcess::start() : The firefox window is launched and I immediately receive the finish signal.

For sure you may ask :) The client (i.e. god) wants to launch a sequence of jobs with the guaranty that only 1 job will be running at the time. Jobs may be scripts, distant commands, etc. or URLs (on Intranets or whatever...)

anda_skoa
20th January 2015, 14:22
Well, you would have best control obviously when not delegating to an external browser.

One idea for using an external browser could be to make the browser talk to the application.
Something like opening a listening socket with the app and let the browser open an URL that connects to this instead. The deliver some HTML that embeds the actual remote content but also keeps the connection open as long as the page/tab is open.

Cheers,
_

Kaemo
20th January 2015, 15:39
I will discuss your solution with my colleagues and god.
Thank you for your help. I will keep you informed about the choosen solution.