Selenium Webdriver Headless Mode shows blank page - google-chrome

I've been spending the past 2 hours trying to find out why the headless mode screws up my program.
When I disable the Headless mode, everything works fine and I can run the program without problems, however when (--headless) is enabled, my webdriver cant find any elements, since the page is just blank.
I would really appreciate some help, I guess the website is detecting the headless mode and therefor showing a blank page? Is there any way to bypass that?
Here is the list of Arguments im passing my browser:
options.AddArguments("--headless");
options.AddArguments("disable-blink-features=AutomationControlled");
options.AddArguments("log-level=3");
options.AddArguments("--windows-Size=1920,1080");
options.AddArguments("--disable-gpu");
options.AddArguments("--disable-extensions");
options.AddArguments("--start-maximized");
options.AddArguments("--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36");
Did you guys ever encounter that? I found some threads where the issue has been described before, but I couldnt find any solutions..
Thanks :)

I had same your issue and resolved it by below solution
Get userAgent of browser first:
String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");
System.setProperty("useragent",userAgent);
Add it to browser option as below
options.addArguments("--user-agent="+System.getProperty("useragent"));

Related

Chrome websocket dev tools doesn't have hex viewer

I found there is no hex viewer in my Chrome's WebSocket dev tools, as in picture 2, unlike picture 1 on my colleague's computer.
I didn't find corresponding view settings. I tried to reboot my computer and reinstall Chrome, even the beta version, still not work.
Thanks to someone who would help me out!
OS version: macOS Catalina 10.15.7, Chrome version: 87.0.4280.88
picture1 normal view
picture2 no encoding settings
This appears to be a bug in Chrome 87. I suspect that your colleague is using a different Chrome version.
See https://bugs.chromium.org/p/chromium/issues/detail?id=1151164#c7, which claims that the bug was fixed in Chrome 89.0.4348.0. The solution appears to be one of:
Switch to the Chrome Beta channel
Use a debug extension for Chrome such as WebSocket Frame Inspector as suggested here.
See also these related SO questions:
How can I change the binary message display format in the Chrome/Edge debugger?
Chrome DevTools. The encoding switch bar of the websocket frame viewer disappeared

on desktop, how to view the source code of the mobile version of a website

I have created a website that displays different source code depending on whether the user is using a desktop or mobile device.
In Chrome on desktop, I can easily view the source code of the desktop version of any website simply by right-clicking anywhere on the website and then choosing "View Page Source".
In Chrome on desktop, is there a way that I can view the source code of the mobile version of a website? I know that in developer tools I can view websites using the mobile emulator, and I can inspect elements as rendered to the mobile browser. However, I have not yet figured out how to view the raw source code rendered to the mobile browser.
To view raw source of mobile version. From developer tools window, on Network tab, select request that retrieve page of interest.
On right pane, activate Response tab. The original source is in Response payload window.
You can check https://developers.google.com/web/tools/chrome-devtools/debug/remote-debugging/remote-debugging?hl=en
Basically you connect your mobile to you pc/mac and you can use your desktop chrome to inspect the pages you render with your mobile and even control it from there.
I haven't been able to find a reliable solution so just end up using curl in the terminal:
curl -H "user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1" https://url/to/inspect
For ease can save as a simple bash script fetch-mob-src.sh:
#!/bin/bash
user_agent="Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"
curl -XGET -H "user-agent: $user_agent" $1
E.g. ./fetch-mob-src.sh https://url/to/inspect

HTML5 video/audio player on mobile Safari (iOS 7 & iOS 10) excludes cookies

I have noticed that the HTML5 video/audio player (AppleCoreMedia) on mobile Safari on iOS 7 excludes all cookies, even first-party cookies. Not even sessions cookies are included in the HTTP-header. This makes it impossible to relay on cookie authorization when playing a video clip in mobile Safari on iOS 7.
All cookies are included correctly running iOS 6 but on iOS 7 no cookies are included in the HTTP-header of AppleCoreMedia.
Can some one else confirm this issue on iOS 7?
Steps to reproduce is:
Create a cookie on a web page.
Play a HTML5 video clip on the same web page using mobile Safari in iOS 7.
Check the server logs for AppleCoreMedia and look for the cookie.
Update 2016-09-20: The video player in iOS 10 (AppleCoreMedia) is not able to read session cookies. Only cookies set with an expire date is readable by the video player.
For iOS10, if you respond with a 403 forbidden, AppleCoreMedia will somehow try again but this time with the missing cookies. If you have code that redirects to login page when the session cookie is missing, video will not work on iOS 10.
I have developed a simple test where you can check if your iOS device have this bug.
Read more about the test here!
The bug continues to exists in iOS 7.1
Obviously Apple is ignoring this bug and I can not understand why since it affects so many users.
I have been running some tests on a iOS 7.1 device that had this problem and it is pretty clear that the bug is related to the private browsing feature. Turning private browsing on and then off fixes the problem on the device.
I'm still seeing problems with iOS 7.0.4, unfortunately. Is the below consistent with what you're seeing or is this perhaps another type of issue?
My test server is running Moodle on Apache and one user can consistently replicate this with two iPads on iOS 7.0.4. The HTTP 407s in the logs below is a Moodle thing. As you can see the cookie is not sent with the range requests:
access_log:
xxx.yyy.zzz.227 - - [22/Nov/2013:23:11:18 +0000] "GET /pluginfile.php/21/mod_videofile/videos/0/trailer_test.mp4 HTTP/1.1" 200 3711807 "http://xyz.bitnamiapp.com/mod/videofile/view.php?id=2" "Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53"
xxx.yyy.zzz.227 - - [22/Nov/2013:23:11:19 +0000] "GET /pluginfile.php/21/mod_videofile/videos/0/trailer_test.mp4 HTTP/1.1" 407 12818 "-" "AppleCoreMedia/1.0.0.11B554a (iPad; U; CPU OS 7_0_4 like Mac OS X; en_us)"
...
forensic_log:
+Uo-kj38AAAEAAH0O5MEAAAAJ|GET /pluginfile.php/21/mod_videofile/videos/0/trailer_test.mp4 HTTP/1.1|Host:xyz.bitnamiapp.com|Referer:http%3a//xyz.bitnamiapp.com/mod/videofile/view.php?id=2|Accept-Encoding:gzip, deflate|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8|Accept-Language:en-us|Cookie:MoodleSession=24gkspshgl8027k3l7p2cor631|Connection:keep-alive|DNT:1|User-Agent:Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53
+Uo-kkH8AAAEAAB2cL4IAAAAA|GET /pluginfile.php/21/mod_videofile/videos/0/trailer_test.mp4 HTTP/1.1|Host:xyz.bitnamiapp.com|Range:bytes=0-1|X-Playback-Session-Id:DF1039A4-571B-4EB8-BFFB-EF07CD730CA2|Accept-Encoding:identity|Accept:*/*|Accept-Language:en-us|Connection:keep-alive|User-Agent:AppleCoreMedia/1.0.0.11B554a (iPad; U; CPU OS 7_0_4 like Mac OS X; en_us)
-Uo-kj38AAAEAAH0O5MEAAAAJ
-Uo-kkH8AAAEAAB2cL4IAAAAA
...
Using iOS 7.0.2, I am seeing cookies included in the request. Here's my user agent header:
User-Agent: AppleCoreMedia/1.0.0.11A501 (iPad; U; CPU OS 7_0_2 like Mac OS X; en_us)
This problem is not yet fixed by Apple. We are continuously receiving reports from our users running iOS 7.0.6 that they are not able to play video clips because no cookies are included in the header.
And for many users, turning safari into private mode, and then back to normal, does not fix the problem.
I have also noted that Dropbox wrote in their blog that they have reverted back to url token authenticating because of problems of these kind with video players.
Apple is continuously ignoring our bug report so this bug will probably not be fixed for a long time.
I'm hearing on the grapevine that iOS 10.2 will contain a fix for this problem
I had the similar issue with Safari. I was using <audio> tag inside the html loaded by jquery. Safari did not include cookies in the request for the audio source, therefore it did not load properly. But somehow it worked after I refreshed the page with CTRL+F5 - it sent cookies with this total reload...
I solved it by adding crossorigin="use-credentials"... Nasty problem.
I had similar problems with cookies on iOS 7.0.3, but they are fixed now with iOS 7.0.4. Let's hope it stays this way.

How does Chrome's "Request Desktop Site" option work?

For iOS google chrome, when a user hits the "Request desktop site" button what does the browser do to try to bring up a desktop site? I imagine some sort of header on the request that sites are looking for, or something similar?
I think the only difference is the User-Agent: header in the request.
Here are the User-Agent headers sent by Chrome on my Android device:
Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19
Notice the word "Mobile' in the first one, and also the mention of Android system and device. Checking these, I see that it also provides false information - namely X11 and x86_64 - to closely match the value sent by the Desktop Linux version of Chrome.
Just wanted to point out that Chrome now not only changes the User-Agent but also ignores the original viewport meta tag if you "Request Desktop Site". Thus it won't be necessary to sniff the User-Agent anymore and you can rely on the viewport change as most responsive sites will automatically do. See this Change for further reference.
One other slight difference is that the request appears to have been to the last intentionally entered URL before any re-directors moved it. For example:
Given: somesite.com sniffs the agent, sees Android, and does a document.location += "/m";
Then: the browser will have a URL of somesite.com/m
But: if you "Request desktop site" it will change the User-Agent and re-request from somesite.com
Unless: you had gone directly in on the mobile URL of somesite.com/m in the first place, in which case it just reloads somesite.com/m.
I would expect that this works with HTTP 301 and 302 redirects, I know it works with document.location changes (at least as described), and would speculate that it works with <meta> refreshes.
This javascript snippet will effectively do the same :
function requestDesktopSite() {
document.getElementsByTagName('meta')['viewport'].content='min-width: 980px;';
}
<button onclick="requestDesktopSite()">Request Desktop Site</button>

Mimicking iPhone user agent in Chrome? [duplicate]

This question already has answers here:
User Agent Switcher for Chrome
(7 answers)
Closed 8 years ago.
I'm tinkering with a phpbb mod which adds a skin for mobile phones, and to work on it in my computer I want to mimic an iphone. In Firefox I manage to do this using the "user agent switcher" extension which comes with built-in "iphone" feature:
https://addons.mozilla.org/en-us/firefox/addon/user-agent-switcher/
However, in Chrome (which I prefer) I cannot make this happen. I downloaded what seemed to be the relevant extension:
https://chrome.google.com/extensions/detail/aafciojnlamllgpkpdkbamkfgbofhgcj?hl=he
It doesn't come with a built-in iPhone mode, so I added the following user agent:
"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3"
However, this seems to have absolutely no effect - the pages load normally and not in the mobile skin.
With the latest release in the Chrome Dev Channel (version 18) you can browse to developer tool settings and change the user agent string directly without needing any plugins or command line options.
First download Chrome from the developer channel, restart it, CTRL+SHIFT+I and click settings on bottom right. You should now be able to select the UA string.
You can change chrome user agent by running it from command line:
chrome.exe --user-agent="User Agent String"
check out This Page for more information
The User-Agent Switcher for Chrome works nicely, I just tested it out.
I downloaded the portable version of chrome and created a custom shortcut to it to always have a mobile browser.
F:_SOE\Apps\GoogleChromePortable\GoogleChromePortable.exe --user-agent="Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3"
There is now the Ultimate User Agent Switcher in the Chrome Webstore. It's awesome!
I don't think chrome can do that but using one of the proxy out there you would be able to do it like privoxy