与GeckoFX 29.0 VB.NET一起使用AutoJSContext时出现Xpcom错误

时间:2016-03-07 17:57:31

标签: vb.net geckofx

我正在使用GeckoFX 29.0和AutoJSContext,当我启动我的应用程序时,它给了我以下错误:

Xpcom.Initialize must be called before using of any xulrunner/gecko-fx services

我知道我必须在调用AutoJS之前初始化Xpcom但是在我的代码中XPcom(xullrunner)在Sub命名为“GeckoFxError”之前初始化

Sub New()
        InitializeComponent()

        Gecko.Xpcom.Initialize(Environment.CurrentDirectory + "/xulrunner")
        Gecko.GeckoPreferences.Default("extensions.blocklist.enabled") = False
        Timer1.Enabled = True
    End Sub
    Sub New1()
        Dim _memoryService = Xpcom.GetService(Of nsIMemory)("@mozilla.org/xpcom/memory-service;1")
        _memoryService.HeapMinimize(False)
    End Sub

    Private Sub GeckoFXerror(sender As Object, e As Gecko.JavascriptErrorEventArgs) Handles GeckoWebBrowser1.JavascriptError
        Dim text As String = "window.alert = function(){};"
        Dim text2 As String = "window.confirm = function(){};"
        Dim text3 As String = "window.open = function(){};"
        Dim text4 As String = "window.prompt = function(){};"
        Using context As AutoJSContext = New AutoJSContext(GeckoWebBrowser1.Window.JSContext)
            Dim result As String = ""
            context.EvaluateScript(text, result)
        End Using
        Using context As AutoJSContext = New AutoJSContext(GeckoWebBrowser1.Window.JSContext)
            Dim result As String = ""
            context.EvaluateScript(text2, result)
        End Using
        Using context As AutoJSContext = New AutoJSContext(GeckoWebBrowser1.Window.JSContext)
            Dim result As String = ""
            context.EvaluateScript(text3, result)
        End Using
        Using context As AutoJSContext = New AutoJSContext(GeckoWebBrowser1.Window.JSContext)
            Dim result As String = ""
            context.EvaluateScript(text4, result)
        End Using
    End Sub

感谢您的帮助,我认为这很容易解决,但我在一个多小时内没有找到任何解决方案

1 个答案:

答案 0 :(得分:1)

在调用labelText: "<b>[[value]] BILLION</b><br>[[category]]" 之前设置Gecko.Xpcom.Initialize(Environment.CurrentDirectory + "/xulrunner"),它应该有效。