开关无法使用DotNetBrowser无头

时间:2018-04-21 07:43:49

标签: chromium dotnetbrowser

我用DotNetBrowser开了一张票,但周一他们将在办公室,希望我能从你们那里得到一些专家意见。

我想用铬开关启动DotNetBrowser,但它对我不起作用。

更新#1:

我的应用程序是控制台(不是Windows窗体),这是我的完整代码

'Some kind of static class to hold some objects globally
Module GlobalObjects
   Public browserwindobj As BrowserWindow
   Public ChromeUserProfilePath as String
End Module

'Main Module
<STAThread>
Public Sub Main(args() As String)
   GlobalObjects.browserwindobj= New BrowserWindow()
   GlobalObjects.browserwindobj.BeginSession()
End Sub

'Browser Window Class
Public Class BrowserWindow
  Dim WithEvents wb As Browser
  Dim m_browsercontext As BrowserContext
  Dim WithEvents NetworkDelegateObj As DelegateNetworking

  Sub BeginSession()
      Start.AddUILog("Starting session...")
      Start.DelayCloser()          

      CreateBrowser()
      NavigateToURL()
      m_sessionstatus = TimerState.Running
  End Sub

   Private Sub CreateBrowser()
    Try
        Start.AddUILog("Creating internal browser...")
        BrowserPreferences.SetUserAgent("UserAgent_HERE")
        Dim chrmswitches As New List(Of String)
        chrmswitches.Add("--disable-web-security")            
        chrmswitches.Add("--reduce-security-for-testing")
        chrmswitches.Add("--allow-running-insecure-content")
        chrmswitches.Add("--ignore-certificate-errors")            
        chrmswitches.Add("--unsafe-pac-url")
        chrmswitches.Add("--no-sandbox")

        GlobalObjects.ChromeUserProfilePath = modGeneral.softwarePath & "\_temp\" & modGeneral.GenerateID("Profile ", True)
        Dim contextparam As New BrowserContextParams(ChromeUserProfilePath)

        If GlobalObjects.SettingsObj.EnableProxies = True Then                
            contextparam.ProxyConfig = New URLProxyConfig("http://PAC_FILE_URL")
        Else
            Start.AddUILog("Proxies usage is disabled by the user")
        End If

        Dim context As New BrowserContext(contextparam)
        context.NetworkService.ResourceHandler = New DelegateAjax
        context.NetworkService.CertificateVerifier = New DelegateCertificateVerifier
        NetworkDelegateObj = New DelegateNetworking()
        context.NetworkService.NetworkDelegate = NetworkDelegateObj
        m_browsercontext = context
        If GlobalObjects.SettingsObj.CPUBased = True Then
            chrmswitches.Add("--disable-gpu")
            chrmswitches.Add("--disable-gpu-compositing")
            chrmswitches.Add("--enable-begin-frame-scheduling")
            chrmswitches.Add("--software-rendering-fps=60")
            BrowserPreferences.SetChromiumSwitches(chrmswitches.ToArray)                
            wb = BrowserFactory.Create(context, BrowserType.LIGHTWEIGHT)
        Else
            BrowserPreferences.SetChromiumSwitches(chrmswitches.ToArray)
            wb = BrowserFactory.Create(context, BrowserType.HEAVYWEIGHT)
        End If

        wb.Preferences.AllowDisplayingInsecureContent = True
        wb.Preferences.AllowRunningInsecureContent = True
        wb.Preferences.PluginsEnabled = True
        wb.Preferences.WebAudioEnabled = True
        wb.Preferences.WebRTCIPHandlingPolicy = BrowserPreferences.WebRTCIPHandlingPolicyEnum.DisableNonProxiedUdp
        wb.Preferences.DatabasesEnabled = True
        mous = New MouseControler(wb)                        
    Catch ex As Exception
        Start.AddUILog("Create Browser: " & ex.Message)
        Process.GetCurrentProcess.Kill()
    End Try
End Sub
End Class

更新#2

这是DotNetBrowser日志:

4/21/2018 5:57:08 PM Information Browser - OS name: Microsoft Windows Server 2016 Standard Evaluation []
4/21/2018 5:57:08 PM Information Browser - OS version: 10.0.14393 []
4/21/2018 5:57:08 PM Information Browser - DotNetBrowser build: 1.14.2.0 []
4/21/2018 5:57:08 PM Information Browser - Verifying Chromium binaries... []
4/21/2018 5:57:08 PM Information Browser - Chromium binaries are OK. []
4/21/2018 5:57:08 PM Information IPC - Starting IPC... []
4/21/2018 5:57:08 PM Information IPC - Starting IPC Server... []
4/21/2018 5:57:08 PM Information IPC - Starting IPC Process... []
4/21/2018 5:57:08 PM Information Process - Start Chromium process... [IPC Process Thread]
4/21/2018 5:57:08 PM Information Process - Command line: C:\Users\Administrator\AppData\Local\Temp\2\dotnetbrowser-chromium\60.0.3112.113.1.14.2.0.523c\browsercore32.exe"--port=61259" "--no-sandbox" "--pid=8172" "--crash-dump-dir=C:\Users\Administrator\AppData\Roaming\DotNetBrowser\dotnetbrowser.dmp.dir" "--user-agent=Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MALCJS; rv:11.0) like Gecko" "--disable-surfaces" "--noerrdialogs" "--enable-logging" "--disable-web-security" "--reduce-security-for-testing" "--unsafe-pac-url" "--disable-gpu" "--disable-gpu-compositing" "--enable-begin-frame-scheduling" "--software-rendering-fps=60"  [IPC Process Thread]
4/21/2018 2:57:08 PM Information IPC - Shared Memory Name: 7e8897cf-0d60-45fa-9411-da1ab3467321 [IPC Server Thread]
4/21/2018 2:57:08 PM Information IPC - Creating IPC connection. Connection ID: 0 [IPC Server Thread]
4/21/2018 2:57:08 PM Information IPC - IPC connection has been established. Connection ID: 17099024 [IPC Server Thread]
4/21/2018 2:57:08 PM Information IPC - READ:  OnHelloMessage{type=OnHelloMessage, uid=1, message='cid:0,type:Main'},  []
4/21/2018 2:57:08 PM Information IPC - WRITE: SetNetworkDelegateConfigMessage{type=SetNetworkDelegateConfig, uid=0, browserContextId=0, DisableMessages=False, DisableResourceMessages=False}, SocketInfo{channelId=0, browserId=-1, channelType=Main} [Memory Writer SocketInfo{channelId=0, browserId=-1, channelType=Main}]
4/21/2018 2:57:08 PM Information IPC - IPC is started. []
4/21/2018 2:57:08 PM Information IPC - WRITE: SetAuthServerWhiteListMessage{type=SetAuthServerWhiteList, uid=1, BrowserContextId=0, ServerWhiteList=, DelegateWhiteList=}, SocketInfo{channelId=0, browserId=-1, channelType=Main} [Memory Writer SocketInfo{channelId=0, browserId=-1, channelType=Main}]
4/21/2018 2:57:08 PM Information IPC - Socket connection checker started for ‬‪‬‍‌‌‭‭‬‎‎‪‍‫‫‏‎‭​​‬‎‏‮‮ [Socket Connection Checker SocketInfo{channelId=0, browserId=-1, channelType=Main}]
4/21/2018 2:57:08 PM Information IPC - WRITE: CreateBrowserMessage{type=CreateBrowser, uid=2, channelId=0, contextId=0, cacheDir='C:\Users\Administrator\AppData\Roaming\LKBrowser\_temp\Profile 21417577722\Cache', memoryDir='', dataDir='C:\Users\Administrator\AppData\Roaming\LKBrowser\_temp\Profile 21417577722', currentLocale='en-us', proxyType=2, proxyRules='', proxyBypassRules='', proxyAutoConfigURL='http://PACFILEURL_OMITTED', defaultZoomLevel='0', isOffScreenMode='True', storageType='DISK}, SocketInfo{channelId=0, browserId=-1, channelType=Main} [Memory Writer SocketInfo{channelId=0, browserId=-1, channelType=Main}]
4/21/2018 2:57:08 PM Information IPC - READ:  OnNetworkDelegateReadyMessage{type=OnNetworkDelegateReady, uid=2, browserContextId=0}, SocketInfo{channelId=0, browserId=-1, channelType=Main} []
4/21/2018 2:57:08 PM Information IPC - WRITE: SetNetworkDelegateConfigMessage{type=SetNetworkDelegateConfig, uid=3, browserContextId=0, DisableMessages=False, DisableResourceMessages=False}, SocketInfo{channelId=0, browserId=-1, channelType=Main} [Memory Writer SocketInfo{channelId=0, browserId=-1, channelType=Main}]
4/21/2018 2:57:08 PM Information IPC - Shared Memory Name: 2747a61b-8340-42d3-950a-f88e01c4c4e8 [IPC Server Thread]
4/21/2018 2:57:08 PM Information IPC - Creating IPC connection. Connection ID: 0 [IPC Server Thread]
4/21/2018 2:57:08 PM Information IPC - WRITE: SetAuthServerWhiteListMessage{type=SetAuthServerWhiteList, uid=4, BrowserContextId=0, ServerWhiteList=, DelegateWhiteList=}, SocketInfo{channelId=0, browserId=-1, channelType=Main} [Memory Writer SocketInfo{channelId=0, browserId=-1, channelType=Main}]
4/21/2018 2:57:08 PM Information IPC - READ:  OnNetworkDelegateReadyMessage{type=OnNetworkDelegateReady, uid=3, browserContextId=0}, SocketInfo{channelId=0, browserId=-1, channelType=Main} []
4/21/2018 2:57:08 PM Information IPC - WRITE: SetNetworkDelegateConfigMessage{type=SetNetworkDelegateConfig, uid=5, browserContextId=0, DisableMessages=False, DisableResourceMessages=False}, SocketInfo{channelId=0, browserId=-1, channelType=Main} [Memory Writer SocketInfo{channelId=0, browserId=-1, channelType=Main}]
4/21/2018 2:57:08 PM Information IPC - WRITE: SetAuthServerWhiteListMessage{type=SetAuthServerWhiteList, uid=6, BrowserContextId=0, ServerWhiteList=, DelegateWhiteList=}, SocketInfo{channelId=0, browserId=-1, channelType=Main} [Memory Writer SocketInfo{channelId=0, browserId=-1, channelType=Main}]
4/21/2018 2:57:08 PM Information IPC - IPC connection has been established. Connection ID: 17100944 [IPC Server Thread]
4/21/2018 2:57:08 PM Information IPC - READ:  OnHelloMessage{type=OnHelloMessage, uid=4, message='cid:0,bid:0,type:Browser'},  []
4/21/2018 2:57:08 PM Information IPC - Channel is connected: SocketInfo{channelId=0, browserId=0, channelType=Browser} []
4/21/2018 2:57:08 PM Information IPC - Socket connection checker started for ‬‪‬‍‌‌‭‭‬‎‎‪‍‫‫‏‎‭​​‬‎‏‮‮ [Socket Connection Checker SocketInfo{channelId=0, browserId=0, channelType=Browser}]
4/21/2018 2:57:08 PM Information IPC - READ:          
OnBeforeSendHeadersMessage{type=OnBeforeSendHeaders, uid=5, browserContextId=0, RequestId=1, url=PACURL_OMITTED, method=GET, originalHeaders='User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MALCJS; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Accept-Language: en-us

', overrideHeaders='', renderProcessId=-1, renderFrameId=-1}, SocketInfo{channelId=0, browserId=-1, channelType=Main} []
4/21/2018 2:57:08 PM Information IPC - WRITE: OnBeforeSendHeadersMessage{type=OnBeforeSendHeaders, uid=5, browserContextId=0, RequestId=1, url=PACURL_OMITTED, method=GET, originalHeaders='User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MALCJS; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Accept-Language: en-us

我拿了日志中的所有开关并使用cmd手动运行它们,并且开关确实有效(必须在--port开关之前添加空间)

然后我也使用cmd,测试了这些开关对浏览器core32.exe的影响,但是我得到一个cmd错误,说我需要在--port之前添加空格,一旦我添加了该空间,就会启动浏览器核心进程。

我想知道,问题出在这一行:

4/21/2018 5:57:08 PM Information Process - Command line: C:\Users\Administrator\AppData\Local\Temp\2\dotnetbrowser-chromium\60.0.3112.113.1.14.2.0.523c\browsercore32.exe"--port=61259" "--no-sandbox" "--pid=8172" "--crash-dump-dir=C:\Users\Administrator\AppData\Roaming\DotNetBrowser\dotnetbrowser.dmp.dir" "--user-agent=Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MALCJS; rv:11.0) like Gecko" "--disable-surfaces" "--noerrdialogs" "--enable-logging" "--disable-web-security" "--reduce-security-for-testing" "--unsafe-pac-url" "--disable-gpu" "--disable-gpu-compositing" "--enable-begin-frame-scheduling" "--software-rendering-fps=60" [IPC Process Thread]

"--port就在.exe之后,没有空格将它们隔开。

所以不应该是browsercore32.exe" --port=61259"

嗯,这是我唯一看到为什么没有读取开关的东西。

无论如何,也许这是我完全不知道的其他事情。

更新#3:

Chromium日志仅包含:

[0421/191430.232:ERROR:command_processor.cpp(337)] IPC: unhandled callback with ID=568
[0421/191430.299:WARNING:pref_notifier_impl.cc(23)] Pref observer found at shutdown.
[0421/191430.299:WARNING:pref_notifier_impl.cc(23)] Pref observer found at shutdown.
[0421/191430.314:WARNING:pref_notifier_impl.cc(23)] Pref observer found at shutdown.
[0421/191430.314:WARNING:pref_notifier_impl.cc(23)] Pref observer found at shutdown.

此外,如果我使用cmd aganist chrome.exe运行--unsafe-pac-url,它的效果非常好。

0 个答案:

没有答案