Skip to main content

New HTML2EXE APIs: App Version and Request Header Injection

Two practical APIs were recently added to HTML2EXE. You can now read the packaged app version at runtime and inject custom HTTP headers for matched requests.

New APIs Overview

  1. window.HTMLPackHelper.getVersion()
  2. window.HTMLPackHelper.setRequestHeaders(urlPattern, headers)
  3. window.HTMLPackHelper.removeRequestHeaders(urlPattern)

1) App Version API: getVersion

What it does

Returns the app version configured during packaging.

Common use cases

  • Show the current version in an About page.
  • Send version info in logs for easier issue diagnosis.
  • Compare with server-side latest version and show update tips.

Example

const version = window.HTMLPackHelper.getVersion();
console.log('Current app version:', version);

// If version is not configured, it returns "1.0.0.0" by default.

2) Request Header API: setRequestHeaders

What it does

Adds custom HTTP headers to requests that match a URL pattern.

Common use cases

  • Attach Authorization tokens to API requests.
  • Add channel/source headers such as X-Channel.
  • Append client version (X-App-Version) for backend analytics and compatibility checks.

Example: add headers

window.HTMLPackHelper.setRequestHeaders('https://api.example.com/*', {
Authorization: 'Bearer your-token',
'X-Channel': 'html2exe-client',
'X-App-Version': window.HTMLPackHelper.getVersion(),
});

Example: remove headers

window.HTMLPackHelper.removeRequestHeaders('https://api.example.com/*');

Read version once during app startup, then inject it into request headers:

const appVersion = window.HTMLPackHelper.getVersion();

window.HTMLPackHelper.setRequestHeaders('https://api.example.com/*', {
'X-App-Version': appVersion,
});

Notes

  1. These APIs are available only when API support is enabled during packaging.
  2. Keep urlPattern scoped to your target domain to avoid unintended side effects.
  3. Remove unused header rules with removeRequestHeaders when they are no longer needed.