Using Proxies in CefSharp chromium browser - Camf ∆ - Nov 8, 2019
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
RE: Using Proxies in CefSharp chromium browser - Camf ∆ - Nov 10, 2019
anyone? :( still need to figure this out
RE: Using Proxies in CefSharp chromium browser - Eternal Darkness - Nov 10, 2019
https://github.com/cefsharp/CefSharp/wiki/General-Usage#proxy-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.
(Oct 26, 2019 10:47 PM)Eternal Darkness Wrote: Some Converters:
https://converter.telerik.com/
https://www.carlosag.net/tools/codetranslator/
https://codeconverter.icsharpcode.net/
https://www.developerfusion.com/tools/convert/csharp-to-vb/
https://www.dotnetspider.com/convert/Csharp-To-Vb.aspx
https://www.tangiblesoftwaresolutions.com/product_details/csharp-to-vb-converter.html
|