openstreetmap / operations

OSMF Operations Working Group issue tracking
https://operations.osmfoundation.org/
99 stars 12 forks source link

Tile downloads with newer Android System Webview implementations fail #601

Closed woheller69 closed 2 years ago

woheller69 commented 2 years ago

Expected behavior

OpenStreetMap tiles should load

Actual behavior

Tiles are not loaded

Links and screenshots illustrating the problem

Install Android System WebView 99.0.4844.58 Try to load (tested with Jelly Browser which uses WebView): https://tile.openstreetmap.de/7/63/42.png -> this works Now change ".de" to ".org" -> "[Access denied. See https://operations.osmfoundation.org/policies/tiles/)" Switch to an older WebView Implementation (tested with 88.0.4342.152) -> this works

The browser uses a valid HTTP User-Agent, so why is it getting blocked?

My RadarWeather app which uses WebView also does not work anymore. https://github.com/woheller69/weather woheller69/weather#54 Switching to ".de" solves the problem for the moment but is not satisfying.

tomhughes commented 2 years ago

Duplicate of #600.

tomhughes commented 2 years ago

If you have proof of a request which meets the policy and which is being rejected then please add it to #600 and we can reopen that to track the issue.

woheller69 commented 2 years ago

What can I do? I am just using a plain webview in my RadarWeather app.

    webView = findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("file:///android_asset/rainviewer.html?lat=" + latitude + "&lon=" + longitude + "&appid=" + API_KEY + "&nightmode=" + nightmode + "&hour12=" + hour12 + "&tz="+timezoneseconds);

No changes to user agent or whatever.

Firefishy commented 2 years ago

What can I do? I am just using a plain webview in my RadarWeather app.

    webView = findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("file:///android_asset/rainviewer.html?lat=" + latitude + "&lon=" + longitude + "&appid=" + API_KEY + "&nightmode=" + nightmode + "&hour12=" + hour12 + "&tz="+timezoneseconds);

No changes to user agent or whatever.

In the above code, it will then use a generic HTTP User-Agent that doesn't identify your application and that is why the access would have been blocked. You need to use something like:

webView.getSettings().setUserAgentString("User-Agent-String-to-Identify-App");
woheller69 commented 2 years ago

How should that user agent look like? Should I append "RadarWeather" to the default string? Can you give an example?

Webview is sending an X-Requested-With header which tells the app behind the request.

I guess all Android apps using the OSM tiles will fail with this change...

tomhughes commented 2 years ago

Well Name/Version is the official syntax but it mostly doesn't matter so long as it's something we can google to find you if there is a problem.

woheller69 commented 2 years ago

Can I append this info to the default user agent string which contains data other sites will need?

woheller69 commented 2 years ago

So something like:

    webview.getSettings().setUserAgentString(WebSettings.getDefaultUserAgent(context)+"RadarWeather");
woheller69 commented 2 years ago
 webView.getSettings().setUserAgentString(WebSettings.getDefaultUserAgent(this)+" "+BuildConfig.APPLICATION_ID+"/"+BuildConfig.VERSION_NAME);

does not work.

    webView.getSettings().setUserAgentString(BuildConfig.APPLICATION_ID+"/"+BuildConfig.VERSION_NAME);

works. But I don't think this is a good solution as all other device information is lost which might be needed by other sites opened with this app

woheller69 commented 2 years ago

I am sure this will lead to tons of problems with apps using the built in Android Webview - which is a web browser - to display tiles. You could get this info by evaluating the X-Requested-With header without impacting the existing apps

woheller69 commented 2 years ago

Another question: Why does this problem only occur on newer webview versions and not with old versions or with the new Beta version as noted in #600?