Error 403 when using local files - referer missing - can I use User Agent and what should it contain

I have been creating HTML files to show GPX tracks. These files are stored on my hard disk. They use Openlayers which uses OSM tiles. Recently I have been getting 403R error blocks with the message:-

Referer is required by
tile usage policy of
to OpenStreetMap’s
volunteer-run servers:
osm.wiki/Blocked
I am using these files in a Windows program using the WebView2 embedded browser.
I can change the User Agent in this if that would fix the problem.
I am having difficulty finding what this should contain.
Can anyone help.

1 Like

The issue you’re seeing is not related to the User-Agent, but to the missing Referer header.

OpenStreetMap’s tile servers require a valid Referer as part of their tile usage policy (see: Blocked tiles - OpenStreetMap Wiki). This is mainly to prevent anonymous or bulk usage from non-identifiable clients.

See Access blocked on osm.org

And Access blocked on osm.org - #31 by pnorman specifically that mentions file:// as problematic and unsolved right now, in the last sentence.

From the link provided it looks like I should wait and see if the problem goes away.

Thanks for the information

If you can change the user-agent then that’s the means you should be using to identify your program. The discussions around file:// URLs are how to make sure identifying information is sent when used by a browser.

I have set the webview2 user agent to a value as suggested in the tile usage policy and am now having no 403 errors. Thanks for the advice

I am using this on Edge WebView2 a browser in a Windows program.

My user agent string is below

User-Agent: MapDataViewer.exe (+file:///C:\Users\iain\Documents\Progs\MapViewer\Maps\AllGPX.html;)

The first part is my program. The second part the HTML file being used

I hope this may help

Hello,

I am unable to resolve this problem despite seemingly adhering to the policy rules:

1)user-agent:“Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0”

2)Referrer:

  • with add in balise meta:
  • or with add in body of file html:

        var layer =L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
                        attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors;',
                        maxZoom: 19,
                        referrerPolicy: 'strict-origin-when-cross-origin' //Pb Error 403R acces blocked usage policy
                        }).addTo(map);

My cross-platform application is written in Delphi 11.2 with a basic Twebbrowser component (windowsengine=IEonly). The 403 error is identical when running on Windows or Android 12. The HTML execution in Delphi is as follows:

        WebBrowser.URL   :='file://'+Vurlstr;
        WebBrowser.Navigate;

Thank you if you have any ideas for a solution. Best regards.

step one would be to check send requests - is referer http header included?

1 Like

It appears that you should identify your app by a name in the user agent. This is part of of the data sent in the header of the request. With the Edge webview2 I have been able to trap this before the request is sent and the user agent is one of the header strings as shown below

Request no 1

Method GET
header0 [Accept, /]
header1 [User-Agent, User-Agent: MapDataViewer.exe (+file:///C:\Users\iain\Documents\Workfiles\Webdev\Dev\AllGPX.html;)]
header2 [sec-ch-ua, “Not-A.Brand”;v=“24”, “Microsoft Edge”;v=“146”, “Chromium”;v=“146”, “Microsoft Edge WebView2”;v=“146”]
header3 [sec-ch-ua-mobile, ?0]
header4 [sec-ch-ua-platform, “Windows”]
URL = https://cdn.jsdelivr.net/npm/ol@v10.8.0/dist/ol.js

I have never found out what the Referer is but the user agent does stop the 403 errors.

1 Like
        L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
        maxZoom: 17,
        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(map);

how to solve or at least debug this?

@holeu , I have merged your question into an existing one that appears to be the same. You could start by reviewing the suggestions that are now above it.

would it be possible to use edge webview2 with Delphi. Google search seem to suggest it is possible

No idea - I suspect that you are best placed to answer that question than anyone else. However, if you’re just trying to open local HTML files then I suspect that you are in the same boat as the people in this other thread, and I’d suggest that you try the options that I suggested there.

Edit: Rereading your earlier answer, it now seems to me like you are saying “yes this works for me” rather than asking if it might; you’re asking if the new person above could possible ttry the change that you made?

This depends on the context the page is in: If a local file:///, you must instruct your browser to send a user agent that hides the fact that it is a browser. This cannot be done programmatically but only in local browser configuration. If served by a webserver https://, referrer policy must allow the browser to send a referer header. Search the forum on how to make leaflet help with that.

BTW: Thank you for the concise html, I never thought it would be so easy to get that running.

That’s the example from the Leaflet-Tutorial, see https://leafletjs.com/examples/quick-start/

… or a little bit different at the wiki: DE:Leaflet Simple Example - OpenStreetMap Wiki

If you have python installed, a possible workaround is to run the simple built-in webserver in the directory that your files are in. I tested it with @holeu ‘s example page and it worked for me.

python -m http.server –-bind 127.0.0.1

1 Like

For these using browsers to display the map in both Chrome and Edge you can test if changing the User Agent solves the problem by using the Developer Tools. Ctrl+Shift+I keys open these.

On Edge you want the Network Conditions tool. If it is not shown click the + at the end of the listed tools then select the Network Conditions. The User Agent tool will be shown

On Chrome select Application. The User Agent tool is at the bottom.

On Both unclick the Use browser default and enter your user agent string.

Do NOT close the Dev Tools as this switches back to default. You can reduce the tools space by hovering your cursor over the boundary line until a double headed arrow is shown then drag it to reduce the size

Open your html file in this tab and test for errors. It will not work in other tabs.

If this works OK in the extensions store there are User Agent switchers. I have not used these and cannot recommend any.

The HTML/Javascript code displays the User Agent

Show User Agent
 <input type="button" onclick="showUA()" id="showBtn" value="Test"><br />
<p id="UA"></p>

<script>
    function showUA() {
        var uag = navigator.userAgent;
        document.getElementById("UA").innerHTML = uag;
    }
</script>

I tried to change user agent in Chrome Dev Tools, with some agents everything worked correctly, with some it did not. So here is how I solved my problem:

< meta name=“referrer” content=“strict-origin-when-cross-origin” >

DeepSeek told me this. It is not working in a single HTML file, but on a web-server it goes quite well.

I’m developing a small application using Qt to curate databases of organism’s DNA sequences. A feature that is very relevant is to map the individuals on a world map in order to check for errors in species’s assignments. For that, I used a widget that requests a page from OSM using

https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png

together with the javascript leaflet.js.

The problem is that OSM server sometimes responds with some blocked tiles (see this image). Apparently it has to do with a HTML referrer header, but that is something I cannot control in my application. I have a static page that grabs leaflet.js javascript and CSS and requests the map to OSM tile server. Interestingly, changing the server to the german (de) tile server apparently solves the problem (see this discussion at Qt forum). I wonder why.

I’m not sure if this is the way to proceed, that is, directly linking to OSM servers to get a map. I only need a world map on a resolution that should not need to go beyond OSM’s zoom level 4 (currently the prototype works with zooms 1 to 4).