Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Using Proxies in CefSharp chromium browser

Hey guys, getting back into the VB game  🙂

I've pulled up one of my old projects which helped me access web browsers via a certain proxy to login to a social media account via the selected proxy.

After testing it out, everything still works; but the web browser in visual basics is outdated. I found a workaround using CefSharp and chromium, it seems to work the only issue I'm having after recreating everything using the cefsharp browser is the proxy function isn't working anymore. I'm not getting any errors using the same proxy method as the original program.

Can anyone help me out?


The button that opens up the second browser with proxy and new cefsharp browser:

Code
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
       Form2.Show()
       MessageBox.Show("You are now under proxy " + Label9.Text + " for the account " + Label7.Text)
       UseProxy(Label9.Text)
   End Sub


The code I'm using for the proxy settings:

Code
Imports System.Runtime.InteropServices
Imports CefSharp
Imports CefSharp.WinForms

Public Class Form1

   <Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)>
   Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
   End Function

   Public Structure Struct_INTERNET_PROXY_INFO
       Public dwAccessType As Integer
       Public proxy As IntPtr
       Public proxyBypass As IntPtr
   End Structure

   Private Sub UseProxy(ByVal strProxy As String)
       Const INTERNET_OPTION_PROXY As Integer = 38
       Const INTERNET_OPEN_TYPE_PROXY As Integer = 3

       Dim struct_IPI As Struct_INTERNET_PROXY_INFO

       struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
       struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
       struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")

       Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))

       Marshal.StructureToPtr(struct_IPI, intptrStruct, True)


The code within my 2nd browser containing the cefsharp browser:
Code
Imports System.Runtime.InteropServices
Imports CefSharp
Imports CefSharp.WinForms

Public Class Form2

   <Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)>
   Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
   End Function

   Public Structure Struct_INTERNET_PROXY_INFO
       Public dwAccessType As Integer
       Public proxy As IntPtr
       Public proxyBypass As IntPtr
   End Structure

   Private Sub UseProxy(ByVal strProxy As String)
       Const INTERNET_OPTION_PROXY As Integer = 38
       Const INTERNET_OPEN_TYPE_PROXY As Integer = 3

       Dim struct_IPI As Struct_INTERNET_PROXY_INFO

       struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
       struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
       struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")

       Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))

       Marshal.StructureToPtr(struct_IPI, intptrStruct, True)

       Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
   End Sub

   Private WithEvents browser3 As ChromiumWebBrowser


   Public Sub New()

       ' This call is required by the designer.
       InitializeComponent()

       ' Add any initialization after the InitializeComponent() call.

   End Sub
   Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load



       browser3 = New ChromiumWebBrowser("https://google.com") With {
        .Dock = DockStyle.Fill
         }
       Panel1.Controls.Add(browser3)

   End Sub

   Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
       browser3.Load(TextBox1.Text)
   End Sub


adding the UseProxy to the navigate button on form2 didnt do anything :\

Code
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        UseProxy(Form1.Label9.Text)
        browser3.Load(TextBox1.Text)

    End Sub
Just a hippie in his bag.
anyone? :( still need to figure this out
Just a hippie in his bag.
https://github.com/cefsharp/CefSharp/wik...resolution (Seems to only take a command line argument/at runtime via Preferences feature, specifically links to first couple stackoverflow links)
https://stackoverflow.com/a/36106994
https://stackoverflow.com/a/37461387
https://stackoverflow.com/a/51723988
https://stackoverflow.com/a/42376097
https://stackoverflow.com/a/43747697
https://stackoverflow.com/a/31168180
https://magpcss.org/ceforum/viewtopic.php?t=14560

Try some of this. Reply back with what method you got working (if any).
Haven't touched projects using browser controls like CefSharp in years, not sure anything is relevant here. Give it a shot tho.

Converters (Click to View)
I post my opinions, please try not to be offended... I am not saying I am superior, but my interpretation of what you are saying may be befuddling.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by hankmoneymanFeb 21, 2026 07:36 AM 1 144 Feb 21, 2026 07:36 AM
Last Post: sudowoodoking
[Python] by 0u1lawSep 6, 2020 02:52 AM 3 220 Sep 6, 2020 02:52 AM
Last Post: Argonaut.exe
[.NET] by v.e.n.o.mJun 14, 2018 11:26 PM 0 118 Jun 14, 2018 11:26 PM
Last Post: v.e.n.o.m