casolorz
casolorz

Reputation: 9604

Other than user agent, what else does Chrome desktop mode do?

I have an Android browser that uses the WebView. I allow my users to switch the user agent and I've added a few user agents, one of which is the desktop mode user agent Chrome uses. The desktop mode user agent works great on some sites but on others it doesn't, however Chrome can request a desktop site on those websites just fine.

So what else is Chrome doing?

Thanks.

Upvotes: 2

Views: 2264

Answers (2)

Rey Rey
Rey Rey

Reputation: 1

webview.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {

            view.loadUrl(request.getUrl().toString());
            return false;
        }
    });

    webview.getSettings().setMinimumFontSize(12);
    webview.setInitialScale(150);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setLoadWithOverviewMode(true);
    webview.getSettings().setUseWideViewPort(false);
    webview.getSettings().setSupportZoom(true);
    webview.getSettings().setBuiltInZoomControls(true);
    webview.getSettings().setDisplayZoomControls(false);
    webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webview.setScrollbarFadingEnabled(false);
    webview.getSettings().setAppCacheEnabled(false);
    webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    String newUA= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19";
    webview.getSettings().setUserAgentString(newUA);
    webview.loadUrl(  ipAddress + "/wordpress/resume/");
    webview.reload();

Got it to load Wordpress site in desktop mode because one plugin like to pull columns.

Upvotes: 0

Josh Lee
Josh Lee

Reputation: 177855

It also ignores any viewport meta tag and uses the default width of 980px. Source: https://crrev.com/5252baa9fbff3f1ffda51a4390cdf43070af22d7

Some web sites switch between desktop and mobile purely based on user agent sniffing, but others just use responsive CSS (and reasonable event handlers). You can identify a responsive site from desktop chrome by enabling device emulation in Chrome's developer tools: The site will immediately transform into the mobile version.

WebView doesn't seem to support this desktop mode exactly. Setting setUseWideViewPort(true) and setLoadWithOverviewMode(true) might be similar, but I'm not sure. See Force webview to display desktop sites, which links to a WebView subclass that provides a lot of additional functionality.

Upvotes: 2

Related Questions