Home > Enterprise >  Detecting if browser is closed in MATLAB
Detecting if browser is closed in MATLAB

Time:04-17

I am opening an URL in Matlab. The script shall only continue when the browser window has been closed.

How can I detect within a Matlab-Script if the browser is still open or not?

Thanks for the help!

CodePudding user response:

Perhaps you can use the IsRunning()-function in Matlab? I recently saw a similar question:

https://mathworks.com/matlabcentral/answers/360246-check-if-the-programm-is-running-already

CodePudding user response:

So far as I can see, there is no good way to do this.

No browser that I am aware of provides a way for other programs to know what URLs it has open (for good privacy reasons). And no browser that I am aware of provides a mechanism for a web page to externally signal that it has been closed. There are also a lot of limitations on how a web page can interact with the rest of the system (for good security reasons).

So your only real option is for the web page to continually write content to disk, in a way that is accessible to Matlab and that is known a priori by your code. You can then monitor that content, and when it gets "stale enough" you can conclude that the page was probably changed. This is complicated and error-prone, and will likely confuse users.

There might be some specific aspect of your situation that makes this workable, but in general it is not.

A better solution is just to have a button that the user clicks when they are done with the web page.

  • Related