⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Different proxy for each QWebEngineView instance?

  • How do i set different proxy for each QWebEngineView instance?
    I know about QNetworkProxy::setApplicationProxy(my_proxy); but it affects
    all the instances at one time. in my case i can't afford splitting the "QWebEngineView"s to different applications, as they need to communicate via signals and slots.

  • Hi Arty and everyone,
    Have you found solution for this issue? I experience same problem now with proxy for application level only, not for QWebEngineView/QWebEnginePage or even QWebEngineProfile.

  • Another poor documentation example.. they say "If QNetworkProxy::applicationProxy is set, it will also be used for Qt WebEngine." but what they don't say is HOW: is it read only once at (web page) creation time, checked periodically (at known times, at unknown times) ..because we can change QNetworkProxy::applicationProxy at any time - Does WebEngine get feedback about those changes and how?
    You can do a simple test:

    1. set QNetworkProxy::applicationProxy to use proxy1
    2. Create WebPage
    3. set proxy2 as global
    4. Create WebPage2
      but that is still inconclusive in case WebEngine checks periodically at known (or unknown /e.g. on next page load only/) times

    It is by design (in Blink - Chromium web engine) - it is a real browser and (perhaps for security reasons) it acts like one i.e. one proxy per browser (all tabs/pages)
    The proper way in Blink is (because Blink uses external 'browser' process per page/tab a.k.a. sandboxing) to pass the proxy at creation time using command line parameters (yes per tab/page! btw: you can see external processes in task manager - just open demobrowser with few tabs)... yet documentation is so scarce I'm having hard time finding information about e.g. which has higher priority e.g. if you set proxies both by QNetworkProxy::applicationProxy and by QCoreApplication::arguments() which one will be used?

    I did a quick test with demobrowser - apparently with every request the proxy changes to the current QNetworkProxy::applicationProxy alas we have no exposure to command line per external QtWebEngienProcess.exe or QtWebEngienProcessd.exe and then we have to disable current applicationProxy to have a proxy per tab/page
    NB! This test is still inconclusive e.g. what will happen for page with 10 iframes loading different URLs and applicationProxy changes after first 5 iframes loaded - will remaining 5 iframes use old or new applicationProxy?

    The only alternative is proxy for URL - if that is OK with you. There are many plugins that apply different proxies per URL e.g. FoxyProxy
    NB! Proxy per URL is not the same as proxy per tab

    In other frameworks e.g. Chromium in C# with CefGlue there is a way to set proxy per tab (yes it is static - you cannot change it later but at least you have an option to change/set/provide it through --proxy-server=.... command line parameter when you create that external sub process)
    alas in QT you can change QCoreApplication::arguments() only once right before you create the app - QCoreApplication app(argc, argv);
    but this is not exposed (per Web Page/View but only at app level)
    ..and even if it was exposed it conflicts with current behavior i.e. on next page load applicationProxy will override it (not sure - still undocumented when the change occurs i.e. will it use new proxy for the remaining resources of the current page or will it change it on next 'main' page load?)

  • @ThatDud3
    Most useful documentation piece I found there
    It seems to me, for current proxy_config realization it's impossible to have different proxies for several QWebEngineViews in one app. Or we have a small chance to hack this with proxy autoselection at URL level (PAC-script) as app-level proxy. But it still will be unchangeable in run-time.
    Chrome has proxy API for extensions (https://developer.chrome.com/extensions/proxy) but I suppose it won't be available in nearest QT releases.

  • @Heilig
    The original question was 'Different proxy for each QWebEngineView instance?'
    that I read as set-once-and-forget but not as change-later-again-at-runtime
    and setting it once (at creation time) is doable - usually by altering command line of those external sub-processess and adding --proxy-server=host:port which also allows to specify different proxy per protocol - and it will work per individual tab or page instance (as long as QWebEngine creates sub-process per each tab/page)
    alas altering command line for chromium embedded sub-processes is not exposed in the API
    Interesting fact - command line params are actually used but from QApplication::arguments() and we can change them only once by modifying argc/argv before we pass them to QApplication a(argc, argv);
    so my point is - infrastructure is there it is just not exposed to changes (per tab/page) and original command line params are blindly re-used over and over again

    e.g. that is proper way to set/use custom flash plugin/dll location - with this command line argument:

    TLDR; Obviously the Initial command line parameters (or modified argc, argv passed in QAplication constructor into QApplication::arguments()) are used always (send over and over again) on each tab/page creation and sent to its sub-process - alas not exposed for modification(s) in some settings per page or sub-process. If they were exposed I think that would solve proxy-per-tab problem, and I think closing a page and silently creating new one in same tab is a good trade off for solving the dreaded proxy-per-tab problem. Of course it will cause conflicts with currently used QNetworkProxy::applicationProxy - but these are implementation details...

Log in to reply