Page 1 of 2

Use proxy with WebViewGadget?

Posted: Tue Aug 06, 2024 12:38 am
by ricardo
Hi,

How to use a proxy with WebViewGadget?


Thanks in advance

Re: Use proxy with WebViewGadget?

Posted: Tue Aug 06, 2024 4:38 am
by idle
Think you might need to be a bit more specific.
a socks proxy?
a transparent http/https proxy?
a forward http proxy?

this might help
https://developer.mozilla.org/en-US/doc ... _tunneling
https://developer.mozilla.org/en-US/doc ... ds/CONNECT

you will probably need to use Infratec's curl module as HttpRequest functions don't have support for CONNECT
https://www.purebasic.fr/english/viewtopic.php?t=80118

Re: Use proxy with WebViewGadget?

Posted: Thu Aug 08, 2024 10:56 pm
by ricardo
HTTPS proxies for navigate, just to navigate using a different IP.

Sometime ago i used this:

Code: Select all

Structure INTERNET_PROXY_INFO1
  dwAccessType.l
  lpszProxy.l
  lpszProxyBypass.l
EndStructure

#INTERNET_OPTION_PROXY = 38

ProcedureDLL SetProxy1(Proxy.s, Port.l, flags.l=#INTERNET_OPEN_TYPE_PROXY) ; Set proxy for the current session
  ;/ Return 1 if success or 0 if fail
  
  Protected ProxyServer.s = Proxy + ":" + Str(Port)
  Protected PIInfo.INTERNET_PROXY_INFO1
  PIInfo\dwAccessType = flags
  PIInfo\lpszProxy = @ProxyServer
  PIInfo\lpszProxyBypass = @""
  If UrlMkSetSessionOption_(#INTERNET_OPTION_PROXY, @PIInfo, SizeOf(INTERNET_PROXY_INFO1), 0) = #S_OK
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure

Re: Use proxy with WebViewGadget?

Posted: Fri Aug 09, 2024 2:30 am
by idle
This might help assuming it's not node.js specific, see the 2nd code block down
maybe you can do that in the web gadget
https://arh.antoinevastel.com/nodejs/20 ... ncies.html

Re: Use proxy with WebViewGadget?

Posted: Fri Aug 09, 2024 7:01 am
by infratec
In my WebView2Gadget() I do it like this:

Code: Select all

Procedure.i WebView2Gadget(Gadget.i, x.i, y.i, width.i, height.i, URL$, Window.i=#PB_Any, Proxy$="", ProxyBypass$="")
:  
:
:
If Proxy$ = ""
  Options$ + "--no-proxy-server "
Else
  Options$ + "--proxy-server=" + #DQUOTE$ + Proxy$ + #DQUOTE$ + " "
EndIf
If ProxyBypass$ <> ""
  Options$ + "--proxy-bypass-list=" + #DQUOTE$ + ProxyBypass$ + #DQUOTE$ + " "
EndIf

Re: Use proxy with WebViewGadget?

Posted: Fri Aug 09, 2024 7:14 am
by ricardo
infratec wrote: Fri Aug 09, 2024 7:01 am In my WebView2Gadget() I do it like this:

Code: Select all

Procedure.i WebView2Gadget(Gadget.i, x.i, y.i, width.i, height.i, URL$, Window.i=#PB_Any, Proxy$="", ProxyBypass$="")
:  
:
:
If Proxy$ = ""
  Options$ + "--no-proxy-server "
Else
  Options$ + "--proxy-server=" + #DQUOTE$ + Proxy$ + #DQUOTE$ + " "
EndIf
If ProxyBypass$ <> ""
  Options$ + "--proxy-bypass-list=" + #DQUOTE$ + ProxyBypass$ + #DQUOTE$ + " "
EndIf
VebViewGadget is very nice, but is missing some basic funcionalities to be ready to use it in some real GUI.

---------------------------

Last line(s) is missing, if is the last line, then its EndProcedure. But if there are 2 or more lines missing...

Where can i get your WebView2Gadget?

Thanks.

Re: Use proxy with WebViewGadget?

Posted: Fri Aug 09, 2024 7:14 am
by ricardo
idle wrote: Fri Aug 09, 2024 2:30 am This might help assuming it's not node.js specific, see the 2nd code block down
maybe you can do that in the web gadget
https://arh.antoinevastel.com/nodejs/20 ... ncies.html

Hi, thanks.

But this is for use in some http request and not for WebViewGadget i think.

Re: Use proxy with WebViewGadget?

Posted: Fri Aug 09, 2024 7:21 am
by infratec

Re: Use proxy with WebViewGadget?

Posted: Fri Aug 09, 2024 11:09 pm
by ricardo

Thanks. I already download it.

But i dont find examples in the zip.

Where can i find examples?

What differences have with the PB WebViewGadget?

:)

Re: Use proxy with WebViewGadget?

Posted: Sat Aug 10, 2024 8:17 am
by infratec
The example is at the end of the file WebView2Gadget,pbi

Simply load this file and run it.

To use a proxy, you have to set the parameters of WebView2Gadget() (also shown in the example but as comment)

Re: Use proxy with WebViewGadget?

Posted: Sat Aug 10, 2024 8:18 am
by Fred
ricardo wrote: Fri Aug 09, 2024 7:14 am
infratec wrote: Fri Aug 09, 2024 7:01 am In my WebView2Gadget() I do it like this:

Code: Select all

Procedure.i WebView2Gadget(Gadget.i, x.i, y.i, width.i, height.i, URL$, Window.i=#PB_Any, Proxy$="", ProxyBypass$="")
:  
:
:
If Proxy$ = ""
  Options$ + "--no-proxy-server "
Else
  Options$ + "--proxy-server=" + #DQUOTE$ + Proxy$ + #DQUOTE$ + " "
EndIf
If ProxyBypass$ <> ""
  Options$ + "--proxy-bypass-list=" + #DQUOTE$ + ProxyBypass$ + #DQUOTE$ + " "
EndIf
VebViewGadget is very nice, but is missing some basic funcionalities to be ready to use it in some real GUI.
Could you elaborate?

Re: Use proxy with WebViewGadget?

Posted: Sat Aug 10, 2024 10:21 am
by infratec
If you need username and password for the proxy, you have to use

Code: Select all

WebView2AddBasicAuthenticationHandler()
Set a handler which returns the username and password to the webview.

https://learn.microsoft.com/en-us/micro ... abs=csharp

Handler in PB

Code: Select all

 Procedure.i WebView2GadgetBasicAuthenticationRequested(*this.WV2_EVENT_HANDLER, sender.ICoreWebView2, args.ICoreWebView2BasicAuthenticationRequestedEventArgs)
    
    Protected Result.i
    Protected *Gadget.WebView2Gadget_Structure
    Protected *basicAuthenticationResponse.ICoreWebView2BasicAuthenticationResponse
    
    
    Debug "WebView2GadgetBasicAuthenticationRequested with gadget: " + Str(*this\context)
    
    Result = #S_FALSE
    
    *Gadget = FindMapElement(WebView2GadgetMap(), Str(*this\context))
    If *Gadget
      
      args\get_Response(@*basicAuthenticationResponse)
      
      *basicAuthenticationResponse\put_UserName(#WebProxyUser)
      *basicAuthenticationResponse\put_Password(#WebProxyPassword)
      
      Result = #S_OK
    EndIf
    
    ProcedureReturn Result
    
  EndProcedure

Re: Use proxy with WebViewGadget?

Posted: Sat Aug 10, 2024 10:57 am
by infratec
I added this in the example part of WebView2Gadget.pbi
Please download the zip file again.

Re: Use proxy with WebViewGadget?

Posted: Sun Aug 11, 2024 1:23 am
by idle
If you wanted to do that cross platform wouldn't use http request with CONNECT or via curl since flag is missing in httprequest.
Im trying to understand what the question is as there are numerous kinds of proxy. So does this handle https transparent proxy?

Re: Use proxy with WebViewGadget?

Posted: Sun Aug 11, 2024 8:06 pm
by ricardo
idle wrote: Sun Aug 11, 2024 1:23 am If you wanted to do that cross platform wouldn't use http request with CONNECT or via curl since flag is missing in httprequest.
Im trying to understand what the question is as there are numerous kinds of proxy. So does this handle https transparent proxy?
No, i want to do for Windows only.
Yes, transparent proxies, just to be able to navigate with a different IP using some web browser (WebView).