Пример #1
0
        public void addEventListener(string eventName, JSCallback listener)
        {
            if (listener == null)
            {
                return;
            }
            CallbackItem item = null;

            item = API.CreateCallbackItem(eventName, (object[] args) => {
                listener?.Invoke(args);
            });
            API.Apply("addEventListener", eventName, item);
        }
Пример #2
0
        private string RunJS(string command, JSCallback cb = null)
        {
            if (!loaded)
            {
                Log("Page is not loaded yet");
                return("");
            }

            var task1 = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(command);

            task1.Wait();
            var result = Convert.ToString(task1.Result?.Result ?? string.Empty);

            cb?.Invoke(result);
            return(result);
        }
Пример #3
0
    public void AsyncTimedEval(Script code, int milliTimeout, JSCallback callback, JSErrorCallback errorCallback)
    {
        var thread = new Thread(() => {
            try
            {
                code.Evaluate(ctx);
                callback.Invoke();
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    errorCallback.Invoke(ex);
                }
            }
        });
        var timeThread = new Thread(() =>
        {
            try
            {
                Thread.Sleep(Configurations.ScriptTimeout);
                if (thread.IsAlive)
                {
                    thread.Abort();
                    thread.Join();
                    errorCallback(new Exception("max time exceeded"));
                }
            }
            catch (Exception ex)
            {
                Debug.LogWarning("This is impossible!");
                Debug.LogError(ex);
            }
        });

        thread.Start();
        timeThread.Start();
    }