I use qml WebView QT 5.2.
WebView {
anchors.fill: parent
url: "http://google.com"
}
Loaded page content is scaled depending on WebView width. How can I get default scale like in browser?
left picture my WebView, right - Google Chrome
To achieve the same scaling as in Picture 2 from you question , you have to set the user-agent property of WebView to the chrome one as follow :
import QtWebKit.experimental 1.0
...
WebView {
anchors.fill: parent
url: "http://google.com"
experimental.userAgent:"Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"
}
...
[Update]
notice the difference between the 3 images from 3 different user-agent strings
------------------------------------------User-agent Android Browser------------------------------------------------
"Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
------------------------------------------user-agent Chrome Browser------------------------------------------------
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36"
------------------------------------------user-agent Ipad-Macosx/Safari------------------------------------------------
"Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25"
Although this topic is pretty old, I had just encountered the same issue with QT 5.11 in a Ubuntu Touch app. Turned out that I just had to set the following:
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
(or QApplication, respectively)
Note that this must be set before the application instance is created:
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication *app = new QGuiApplication(argc, (char**)argv);
This lead to the webview scaling the same way the native browser on ubuntu touch does (Morph browser). I did not need to set any user agent information.
For those also working with Ubuntu Touch, the MainView size does have a direct impact on content scaling in the webview. I left the defaults set by the creation process (clickable create), which is:
width: units.gu(45)
height: units.gu(75)
This leads to correct scalingon the device (in this case, a Volla Phone).
Related
Please find below XPATH am using to scrape price from Myntra site. I can able to scrape from all other sites except Myntra and same below XPATH is working in my local windows system with Selenium,Python3 version and using chrome driver.
Driver path : driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver", options=chrome_options);
variable_name = driver.find_element_by_xpath('//*[#id="mountRoot"]/div/div/div/main/div[2]/div[2]/div[1]/p[1]/span/strong').text
link for reference: https://www.myntra.com/beauty-gift-set/kama-ayurveda/kama-ayurveda-round-the-clock-skincare-gift-set/12800176/buy
When hosted to EC2 ubuntu machine getting below error:
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="mountRoot"]/div/div/div/main/div[2]/div[2]/div[1]/p[1]/span/strong"}
Tried changing XPATH like driver.find_element_by_xpath('//*[#class="pdp-price"]//*').text but no luck.
Use the below XPath
driver.find_element_by_xpath('//span[#class="pdp-price"]//strong').text
Or by Using the below CSS selector
driver.find_element_by_css_selector('.pdp-price strong').text
The above works only if the site is in GUI mode whereas for headless displays Access Denied attached below screenshot for your reference. Since application blocks headless mode
Add the below user agent argument and load the web driver to your chrome driver options
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--headless")
chrome_options.add_argument(f'user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36')
Just add this user-agent option while launching headless chrome :
--user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
chromeLauncher.launch({
chromeFlags: ["--headless", '--disable-gpu', `--user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"`],
chromePath: '/usr/bin/google-chrome'
})
How do I change the user-agent in a headless Chrome created by Symfony's Panther createChromeClient()?
When I create a Chrome client with
$client = \Symfony\Component\Panther\Client::createChromeClient();
I see in the access_log a user-agent of
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/77.0.3865.90 Safari/537.36"
I searched for solutions, and think I have to change the user-agent string via the arguments of the chrome, but can't find the right way, because the answers on the web aren't for PHP or Panther.
Cheers!
I found it:
$client = \Symfony\Component\Panther\Client::createChromeClient(null, [
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
'--window-size=1200,1100',
'--headless',
'--disable-gpu',
]);
This question gave me the idea.
When I add a content module to a page I get a 404 error.
In the logbook I see the following entry
TabId:
PortalAlias:staging.2-le-marche.com/nl-nl
OriginalUrl:/nl-nl/desktopmodules/2sxc/api/view/Module/GetSelectableTemplates
Referer:http://staging.2-le-marche.com/desktopmodules/tosic_sexycontent/dist/dnn/ui.html?sxcver=8.5.1.26679
Url:http://staging.2-le-marche.com/nl-nl/desktopmodules/2sxc/api/view/Module/GetSelectableTemplates
UserAgent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
My guess is a miss-configuration of DNN and portal domains. That kind of thing can work for quite a while (pages do work) but the js-framework of dnn will then report a (slightly) different url than is actually in use, and end up pointing to a url which doesn't work.
I have two identical calls to ASP.NET, the only difference is the User-Agent. I used Fiddler to reproduce the issue.
The HTTP request line is:
PUT http://localhost/API/es/us/havana/club/tickets/JiWOUUMxukGVWwVXQnjgfw%7C%7C214 HTTP/1.1
Works with:
User-Agent: Mozilla/5.0 (Linux; Android 4.3; Nexus 10 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2307.2 Safari/537.36
Fails with:
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4
Everything else is 100% the same.
In my case, the root cause was MVC's MultipleViews and DisplayMode providers. This allows MVC apps to magically pick up device-specific views; e.g.
custom.cshtml
customer.mobile.cshtml
This article has a good explanation of the functionality as well as details how to turn it off:
https://learn.microsoft.com/en-us/archive/msdn-magazine/2013/august/cutting-edge-creating-mobile-optimized-views-in-asp-net-mvc-4-part-2-using-wurfl
I fixed this by adding Microsoft.AspNet.WebPages package to my project and adding a call to this code in my startup (application_start in global.asax or if using OWIN, the method decordated w/ OwinStartup attribute):
public static void RegisterDisplayModes()
{
// MVC has handy helper to find device-specfic views. Ain't no body got time for that.
dynamic modeDesktop = new DefaultDisplayMode("") { ContextCondition = (c => { return true; }) };
dynamic displayModes = DisplayModeProvider.Instance.Modes;
displayModes.Clear();
displayModes.Add(modeDesktop);
}
When a user is visiting your site, is there a way of know what type of device they are using: computer, tablet, or mobile device? For example, when I get emails sometimes I see that it says sent via iphone; how do they know that? Any help or point me in the right direction would be very helpful.
Short answer: You can't.
Long answer:
All you have is the information in the HTTP User-Agent header, which usually contains the OS name and version.
Usually, browsers running on Mac OS and Linux send enough information to identify the exact OS. For example, here's my User-Agent header:
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.7) Gecko/2009030423 Ubuntu/8.10 (intrepid) Firefox/3.0.7
You can see that I'm running Ubuntu 8.10 Intrepid Ibex.
And here's what Firefox and Safari 4 Beta report on my MacBook Pro:
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.7) Gecko/2009021906 Firefox/3.0.7
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16
Windows browsers, on the other hand, usually only report the OS version and not the specific package (Pro, Business, etc.):
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:x.x.x) Gecko/20041107 Firefox/x.x
I did not write this awnser i copied it from: Detect exact OS version from browser Thanks to: Can Berk Güder