Referring domain name

How to find the domain name sent by htmlexe to remote server? In past have simply used “heserver” in exeout with some success, htmlexe 2024 is not being friendly with me:)

For instance, I have this on a server:

function enableCORS(req, res, next) {
  const allowedDomains = ['example.net', 'heserver', 'example.com'];
  const origin = req.headers.origin;
  const referer = req.headers.referer;

The above worked with exeout but not htmlexe.

Normally can get some info using:

console.log(document.referrer);

Any help / advice / assistance appreciated.

Are you using WebView2 or CEF?

My bad, should have stated that:)

WebView2

In WebView2, the default protocol is not https://heserver but file:///
Maybe that’s the reason why it fails. There is no domain name…
AFAIK https://heserver/ may also work in HTMLEXE but you’ll have to use some redirection in your homepage to switch to the heserver domain. file:/// is, for some reasons, faster in webview2.

Will have to figure that out, thanks.

i am stumped after days of research to get the heserver sent as referrer. Not asking for a full all-out code example, but can you point me in the correct direction?

AFAIK referrer is not sent for HTTPS links. Maybe we could set some Referrer-Policy header.

It would be useful to set something :slight_smile:

I am not sure what is best method but I have been experimenting with WebView2 for few months.

WebView2 does not expose any direct API to set the Referrer-Policy header for every navigation. However, you have some options to influence referrer behavior when loading URLs. Below are ways to handle referrer policies within WebView2:

  1. Set Referrer-Policy in the Server Response Header:
    The easiest method is to configure your web server to include the Referrer-Policy header in its responses. When the WebView2 control navigates to that URL, it will respect the server’s Referrer-Policy configuration.Example (Server-side):
Referrer-Policy: https://whatever-you-choose.com

WebView2 will respect this meta tag when rendering the HTML.

  1. Modify the CoreWebView2 Environment:
    If you control the source URL being loaded in the WebView2, you can set the referrer when calling the Navigate method. This gives you a finer level of control, although it doesn’t set the Referrer-Policy header directly.

Example:

string url = "https://example.com";
string referrer = "https://yourapp.com"; // Custom referrer
webView2.CoreWebView2.NavigateWithWebRequest(url, new HttpRequestMessage(HttpMethod.Get, url) {
    Headers = {
        { "Referer", referrer }
    }
});

Note that the NavigateWithWebRequest API may require you to build the CoreWebView2 environment properly.

Nice to have a form field to choose the referrer.

Disclaimer: At this point I know just enough about WebView2 to be dangerous :slight_smile:

1 Like

Yes, but this would not be effective by default.
It’s on our TODO list.

1 Like

No issue for me any longer. Have found an alternative solution for the projects.

But surely a feature that others (any me) will find useful.

1 Like