Use proxy with WebViewGadget?

Just starting out? Need help? Post your questions and find answers here.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Use proxy with WebViewGadget?

Post by ricardo »

Hi,

How to use a proxy with WebViewGadget?


Thanks in advance
ARGENTINA WORLD CHAMPION
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Use proxy with WebViewGadget?

Post 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
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Use proxy with WebViewGadget?

Post 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
ARGENTINA WORLD CHAMPION
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Use proxy with WebViewGadget?

Post 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
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Use proxy with WebViewGadget?

Post 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
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Use proxy with WebViewGadget?

Post 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.
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Use proxy with WebViewGadget?

Post 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.
ARGENTINA WORLD CHAMPION
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Use proxy with WebViewGadget?

Post by infratec »

ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Use proxy with WebViewGadget?

Post 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?

:)
ARGENTINA WORLD CHAMPION
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Use proxy with WebViewGadget?

Post 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)
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Use proxy with WebViewGadget?

Post 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?
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Use proxy with WebViewGadget?

Post 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
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Use proxy with WebViewGadget?

Post by infratec »

I added this in the example part of WebView2Gadget.pbi
Please download the zip file again.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Use proxy with WebViewGadget?

Post 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?
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Use proxy with WebViewGadget?

Post 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).
ARGENTINA WORLD CHAMPION
Post Reply