Currently using Selenium to test a chrome extension.
One of the features relies on the chrome.idle API to trigger an event when the idle state is not active (meaning no user interaction for a certain duration). This API is supposed to detect when the machine's idle state changes as per the docs.
Weird thing is, the test is run in headless mode via Github Actions, and regardless of that, the idle state is active. You would think a webdriver.sleep() in headless mode would be enough to emulate an idle machine, but apparently not.
Any ideas what could explain this behaviour? And could there be a way to force the browser/machine to be idle during a headless test execution?
Related
I would like to know, whether I'm currently debugging my javascript code?
Background: (Why I need to know)
I have created a page, that spawns a Worker.
When I run this page and press F12 to debug, I set a breakpoint in the Worker. This breakpoint will then get hit when I press my button to run the Worker (so far all good).
Now to prevent that the Worker runs forever I have created a simple timer in the main page, that terminates the Worker after 2 seconds, like this:
timer = setTimeout(function ()
{
worker.terminate();
worker = NewWorker();
}, 2000);
Now the problem: When the breakpoint is hit in Worker, the timer fires 2 seconds later (since the main page thread is still running independantly) and terminates the Worker. So I can't debug the Worker.
My plan is to simply disable (or not start) the timer, when I'm debugging.
So, Is there a way to know, if a debugger is attached?
Update:
My current workaround is to simply comment out the timer code, when I want to debug the Worker, but I would like to do a test.
Update2:
May be a debugger is always attached in the browser, but it's only active when it's visible. Breakpoints are only hit when you have the debugger window open.
So, is there a way to test that?
Well, it seems, there's no answer to this question.
Ideally I would want the browser to break all threads when one thread hit a breakpoint (Visual Studio can do this, but not in javascript).
May be one day browsers will support this.
Update:
Now Visual Studio supports debugging Worker. It's still an experimental feature. You enable it using the weirdly named option in 'Options', 'Debugger':
Enable using the multi-target Javascript debugger for debugging Javascript in applicable targets (requires debugging restart)
To debug a Worker, start debugging your page, then Visual Studio Solution Explorer will show show the Worker.js file. double-click and breakpoints.
However it has not really solved the problem with timers in the main thread firing when you hit a breakpoint in a Worker.
Everytime I try to access this website and open google-chrome-devtools I am unable to inspect any of the elements through the Inspector as the UI is having an overlay along with a message Paused in debugger.
The upvoted and accepted answer of this discussion says to check the Source tab, check under the Event Listener Breakpoints panel if you've set any breakpoints under 'Mouse'. I have cross checked that none of the Sources -> EventListenerBreakpoint are set.
The upvoted and accepted answer of this discussion says to check if the little octagonal stop/pause sign (at lower left of Chrome "Sources") is colored (blue or purple). I am not sure why do I need to do that additionally for selected websites.
Snapshot:
The upvoted and accepted answer of this discussion speaks about the Manual Steps.
All the solutions seem to point towards the manual process. But this issue seems to me the root cause behind Selenium being unable to getPageSource().
Code trials:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("http://rd.huangpuqu.sh.cn/website/html/shprd/shprd_tpxw/List/list_0.htm");
Output: Chrome opens but doesn't navigates to the url.
So my questions are:
In which case can Paused in debugger error occurs?
Is it an error from the frontend development?
How can I bypass this error during the Automated Tests through Selenium?
In which cases can the Paused in debugger error occur?
Anytime you are accessing this page with the dev tools open. The debugger; line will pause javascript execution, but browsers will ignore it if the dev tools are closed.
Is it an error from the frontend development?
In this case, no--they're deliberately trying to keep you out. The purpose of this function is to pause execution and then redirect your browser to a different page if it takes longer than 100ms to resume. I would speculate that this is designed to interfere with automated crawlers like selenium, because a regular user wouldn't be affected and a human developer can just hack around it.
How can I bypass this error during the Automated Tests through Selenium?
My first recommendation would be to try running Selenium headlessly, if that's an option. If not, use the hotkey to resume execution (F8). You can use whatever method you like for generating a keypress; with the java.awt package it will look something like this:
Robot robot = null;
try
{
robot = new Robot();
}
catch(Exception e)
{
//handle failure
}
robot.keyPress(KeyEvent.VK_F8);
Remember that you have to trigger this within 100ms, so use whatever logic you like to detect the block and respond quickly. If you just want something quick and dirty, I would just make it spam F8 keypresses every 50ms for a period of time until you're certain the page has loaded.
EDIT: On further investigation, this page is extremely messy and hostile to anyone with the dev tools open. There is not one but several functions that trigger debugger;and they get called repeatedly on a timer for as long as you're on the page. Running headlessly seems like the best choice, unless you want to continue spamming F8 for the entire session.
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
I'm just wondering if setTimeout based timer will run properly on OS X when the browser running it is out of focus (e.g.: browser is in fullscreen mode and user is on another desktop/application). Does the App Nap feature interfere with running JavaScripts as well?
Yes, it does interfere with any running JS because App Nap prevents "unnecessary" things running in the background in order to save power.
In addition, there isn't any way to disable App Nap for performance reasons.
See this SE post for a little more information.
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.