Is it possible to determine whether the browser process itself runs in the background or in the foreground using Javascript?
I am looking for a method that will let me know if the browser process is in the foreground/background in the OS level (For example if the chrome.exe process is on foreground in the OS).
I noticed that using the Page Visibility WebAPI I can determine whether my tab is in focus, but actually if the tab is in focus but the browser itself is not it still considered as visible.
Clarification - my goal is to update specific data on my client-side just, and just if, the user is for sure watching the browser at the moment. In other words, I have to check that the specific tab in the browser is active (did it with Page Visibility API), and that the browser itself is on top of all the other processes that running on the machine.
Thanks
Related
Is it possible to force a browser window on top of all other windows and work in other windows at the same time?
I'm trying to make a webpage that gives the user extra information. This window needs to stay in front of Avaya interaction center. But ofcourse the user needs to be able to continue working in other browser windows/ apps.
I tried:
`<body onBlur="window.focus()">`
But that prevents users from working in anything else.
Not as a webpage, no. You cannot interact with OS in that manner. If you have an option to deploy your webpage as an Electron app, then you could leverage something like win.setAlwaysOnTop.
You can't interact with the browser for security reasons. Manipulate browser is impossible .
If in your case it's for noble reasons it can be use for bad reason and block users, imagine you put a website in fullscreen and force it in top you can block the computer for basic user. More dangerous actions are also possible if you allow this kind of action.
I have some memory-intensive WebGL code which runs in both desktop and mobile devices. The user is able to add/remove WebGL modules thereby changing the memory requirements for the page. On low-power devices its possible for the user to get themselves into a bad state. They try to load the page, but the page runs out of memory due to too many modules loading. The page crashes. I am working on providing the user with a means of recovering from this scenario.
Some high-level pseudocode for my recovery solution looks like:
During init, write a flag to sessionStorage for each module. The flag indicates the given module has not loaded yet.
If a module already has a flag in storage - don't try to load it.
For every other module - attempt to load.
As each module loads, clear its flag.
Overall, this code has the effect of preventing the browser from attempting to load all modules every time.
However, I also clear a module's load flag if the user refreshes the page. A manual page refresh is not a browser crash -- and thus all modules should continue to try and load:
window.addEventListener('unload', function() { /* clear flags here */ });
This all seems to work fine in desktop environments, but in testing mobile devices I've found that often times the browser refreshes the page automatically instead of crashing. In Safari, I see an error message:
"A problem occurred with this webpage so it was reloaded."
Is it possible to detect a manual page refresh vs a 'browser error recovery' refresh?
To the best of my knowledge the answer is, 'No.' as I only have a window unload event to work with in both scenarios.
I'm using a web framework where everything gets passed through a websocket. New / updated DOM elements are shipped over to the browser, events get shipped back to the server. Works great. Except when the websocket gets closed.
This happens...
when using desktop/mobile Safari's browser navigation buttons are used to leave & come back to the page
on mobile Safari after a timeout when switching to a different app, tab or screen locking
when the WiFi goes down etc.
After that the user simply sees a normal looking page, but everything is obviously dead as no more updates happen and no more events get relayed to the server. I'd like to simply refresh the page in that case. Either everything goes back to normal or the user sees a connection error in case of no network etc.
I tried poking around in the framework's code, adding "window.location.reload(true);" to the "onclose" handler for the websocket kinda does the trick. My state is 100% on the server, so reloading the page will just fix things.
Assuming I can't modify / fix the web framework I'm using, and it doesn't have any onConnectionLost client-side event, what's my best option to detect this scenario and reload the page? Are there any events like 'onPageDisplayedButNotProperlyReloaded', 'onPageVisibleButHasBecomeStaleInTheMeantime', 'onWebSocketsClosed' for me to use? Can I just open some dummy websocket and reload the page when it gets closed or something? Any other good way to detect this?
Thanks!
I developed a web app to display a slideshow, and want to display it on my secondary monitor (Connected via HDMI) with IE's Kiosk mode on Windows 10. Because of CPU and other resources on the shared server, I want to pause the slideshow when the monitor is powered off. (And therefore nobody is seeing it)
Is there a way to detect connected displays from Internet Explorer? Since this is a one-pc kiosk setup, add-ons, etc. are accepted. Triggering javascript/jquery events would be ideal. Thank you!
No, there is no reliable way to detect if a second monitor is physically switched off but still connected via the cable.
I have to ask though: why do you need to physically switch the second monitor off?
As an alternative could you not:
Have the slideshow stop after a timed duration unless it receives an input?
Have the slideshow only on display at certain times of the day?
Accept events from, say, a node server to control when to and not show the slideshow?
Having said that these threads could provided you, albeit unreliably apparently, what you need:
Is there any way to detect the monitor state in Windows (on or off)?
Monitoring a displays state in python?
You can't do in javascript. Why not try some asp component.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162617%28v=vs.85%29.aspx
You could potentially write a command line program that sits on a particular port, continuously checks for that locally and then use HTML5 WebSockets in IE to communicate with it?
i.e. C# PowerModeChangedEvent
SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(
SystemEvents_PowerModeChanged
);
I don't think so....
CPU cycles are paused when the client computer is put into Sleep mode. (win+L)
Start>Control Panel>Power
configures how the monitor(s) behave when the client is powered down or put to sleep mode.
the screen object in js returns the metic values (height/width) of the screen object but not its powered state.
the impact of wasted CPU cycles on a powered down secondary monitor should be un-noticable....
probably you have not selected the option to "Use software rendering instead of GPU rendering" on the Advance tab of internet options....
You will notice that your CPU on your desktop will throttle up and the cooling fan will race if you haven't set the above setting when running graphic intensive web pages or canvas scripts.
I have one web application. When client enters the address and after successfully logging in. He gets the home page with some data over the page. Now when any third party tool or from run command if i give the same url on which the client is with changed parameter values, i want the same browser window to be refreshed with updated/changed values without opening the new browser window.
Whats happening now is that when i'm triggering the url from different source, its opening in new browser window. Plz help me out with few suggestions.
Ars.
The best solution would be for the web application to poll the server and refresh itself when there is an update.
Your command line tool can then contact the server and update the parameters directly, and the application in the user's browser will pick up those changes automatically.
Attaching to a running Internet Explorer instance is also possible, for example see this article: http://www.codeproject.com/Articles/9683/Automating-Internet-Explorer, or the Selenium project at http://seleniumhq.org/. But you're almost certainly going to make it easier for yourself by changing your application to refresh automatically.