How to open a web page in the background after hiding the browser window in C language

Dani AI

Generated

Brief note tied to the existing posts: asked how to "open a web page in the background" from C, and correctly suggested avoiding a typical external browser and embedding a browser control. Hiding another program's window is unreliable and can look like malicious behavior; modern browsers often ignore window-hiding hints and default-browser calls may hand requests to an existing, visible process.

Practical, trustworthy options (ordered by simplicity and reliability):

  • For background network work only (no rendering or JS): perform an HTTP request from the program itself. Using a C HTTP client library (for example, libcurl) is simple, cross-platform, and does not spawn any UI.
  • For full-page rendering (HTML+JS) without showing a UI: use a headless browser engine or an embedded browser (headless Chromium, CEF, or an embedding like WebView2 on Windows). These run a rendering engine inside the app and can be kept invisible.
  • If forcing an external browser to hide: possible on Windows by launching the exact browser process with CreateProcess and STARTUPINFO.dwFlags = STARTF_USESHOWWINDOW plus wShowWindow = SW_HIDE, but many browsers ignore this or reparent windows; this approach is the least reliable.

Minimal example (background fetch with libcurl in C):

#include <curl/curl.h>

int main(void) {
  CURL *c = curl_easy_init();
  if (c) {
    curl_easy_setopt(c, CURLOPT_URL, "https://example.com/");
    curl_easy_perform(c);
    curl_easy_cleanup(c);
  }
  return 0;
}

Troubleshooting and cautions: prefer embedding or headless engines when page scripts must run. Run network work on a worker thread to avoid blocking the UI. Expect antivirus or platform policies to flag apps that spawn hidden browser windows; document intent and use headless/embed approaches to avoid that.

Recommended Answers

All 2 Replies

Which OS? Which C compiler? Also, why do this since it's something a malevolent app might do. Even so, you left out too many details to start looking at possible solutions.

commented: Yes, Windows operating system, specified browser, or default browser,Visual Studio 2019 compiler,When a user uses my exe program, my exe program can +0

Thinking about this I would not use a typical browser. I would never be able to do this in C so I'm guessing you misspoke.

Instead make the usual Windows app with a browser frame/element in the app. Then you have complete control over your app and its elements. Since how to hide your app has been discussed for decades I won't write about that further. But here's Visual Studio and the browser element tutorial: https://www.instructables.com/Making-a-Web-Browser-in-Visual-Studio/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.