diff --git a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp index 61c19455d..6295c02fa 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp +++ b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp @@ -256,6 +256,8 @@ namespace CefSharp auto callbackRegistry = rootObjectWrapper->CallbackRegistry; auto script = argList->GetString(2); + auto scriptUrl = argList->GetString(3); + auto startLine = argList->GetInt(4); auto frame = browser->GetFrame(frameId); if (frame.get()) @@ -267,8 +269,7 @@ namespace CefSharp try { CefRefPtr exception; - //TODO: Add script url and startline as params in browser process - success = context->Eval(script, CefString(), 1, result, exception); + success = context->Eval(script, scriptUrl, startLine, result, exception); //we need to do this here to be able to store the v8context if (success) diff --git a/CefSharp.Core/Internals/CefFrameWrapper.cpp b/CefSharp.Core/Internals/CefFrameWrapper.cpp index bfaa3fd48..fa494c252 100644 --- a/CefSharp.Core/Internals/CefFrameWrapper.cpp +++ b/CefSharp.Core/Internals/CefFrameWrapper.cpp @@ -232,7 +232,7 @@ void CefFrameWrapper::ExecuteJavaScriptAsync(String^ code, String^ scriptUrl, in _frame->ExecuteJavaScript(StringUtils::ToNative(code), StringUtils::ToNative(scriptUrl), startLine); } -Task^ CefFrameWrapper::EvaluateScriptAsync(String^ script, Nullable timeout) +Task^ CefFrameWrapper::EvaluateScriptAsync(String^ script, String^ scriptUrl, int startLine, Nullable timeout) { ThrowIfDisposed(); ThrowIfFrameInvalid(); @@ -242,7 +242,7 @@ Task^ CefFrameWrapper::EvaluateScriptAsync(String^ script, auto client = static_cast(host->GetClient().get()); - return client->EvaluateScriptAsync(browser->GetIdentifier(), browser->IsPopup(), _frame->GetIdentifier(), script, timeout); + return client->EvaluateScriptAsync(browser->GetIdentifier(), browser->IsPopup(), _frame->GetIdentifier(), script, scriptUrl, startLine, timeout); } /// diff --git a/CefSharp.Core/Internals/CefFrameWrapper.h b/CefSharp.Core/Internals/CefFrameWrapper.h index 678c91468..914c94d86 100644 --- a/CefSharp.Core/Internals/CefFrameWrapper.h +++ b/CefSharp.Core/Internals/CefFrameWrapper.h @@ -173,7 +173,7 @@ namespace CefSharp /*--cef(optional_param=script_url)--*/ virtual void ExecuteJavaScriptAsync(String^ code, String^ scriptUrl, int startLine); - virtual Task^ EvaluateScriptAsync(String^ script, Nullable timeout); + virtual Task^ EvaluateScriptAsync(String^ script, String^ scriptUrl, int startLine, Nullable timeout); /// // Returns true if this is the main (top-level) frame. diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index bb4700d1f..b1ed582e2 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -1132,7 +1132,7 @@ namespace CefSharp return handled; } - Task^ ClientAdapter::EvaluateScriptAsync(int browserId, bool isBrowserPopup, int64 frameId, String^ script, Nullable timeout) + Task^ ClientAdapter::EvaluateScriptAsync(int browserId, bool isBrowserPopup, int64 frameId, String^ script, String^ scriptUrl, int startLine, Nullable timeout) { auto browser = GetBrowserWrapper(browserId, isBrowserPopup); @@ -1152,8 +1152,8 @@ namespace CefSharp SetInt64(argList, 0, frameId); SetInt64(argList, 1, idAndComplectionSource.Key); argList->SetString(2, StringUtils::ToNative(script)); - - + argList->SetString(3, StringUtils::ToNative(scriptUrl)); + argList->SetInt(4, startLine); browserWrapper->SendProcessMessage(CefProcessId::PID_RENDERER, message); diff --git a/CefSharp.Core/Internals/ClientAdapter.h b/CefSharp.Core/Internals/ClientAdapter.h index 1e7df0c17..95f256771 100644 --- a/CefSharp.Core/Internals/ClientAdapter.h +++ b/CefSharp.Core/Internals/ClientAdapter.h @@ -196,7 +196,7 @@ namespace CefSharp virtual DECL void OnFindResult(CefRefPtr browser, int identifier, int count, const CefRect& selectionRect, int activeMatchOrdinal, bool finalUpdate); //sends out an eval script request to the render process - Task^ EvaluateScriptAsync(int browserId, bool isBrowserPopup, int64 frameId, String^ script, Nullable timeout); + Task^ EvaluateScriptAsync(int browserId, bool isBrowserPopup, int64 frameId, String^ script, String^ scriptUrl, int startLine, Nullable timeout); IMPLEMENT_REFCOUNTING(ClientAdapter); }; diff --git a/CefSharp/IFrame.cs b/CefSharp/IFrame.cs index f43cf2432..bef10d2f1 100644 --- a/CefSharp/IFrame.cs +++ b/CefSharp/IFrame.cs @@ -116,16 +116,18 @@ namespace CefSharp /// is the URL where the script in question can be found, if any. /// The renderer may request this URL to show the developer the source of the error. /// is the base line number to use for error reporting. - void ExecuteJavaScriptAsync(string code, string scriptUrl = "about:blank", int startLine = 0); + void ExecuteJavaScriptAsync(string code, string scriptUrl = "about:blank", int startLine = 1); /// /// Execute some Javascript code in the context of this WebBrowser, and return the result of the evaluation /// in an Async fashion /// /// The Javascript code that should be executed. + /// is the URL where the script in question can be found, if any. + /// is the base line number to use for error reporting. /// The timeout after which the Javascript code execution should be aborted. /// A Task that can be awaited to perform the script execution - Task EvaluateScriptAsync(string script, TimeSpan? timeout = null); + Task EvaluateScriptAsync(string script, string scriptUrl = "about:blank", int startLine = 1, TimeSpan? timeout = null); /// /// Returns true if this is the main (top-level) frame. diff --git a/CefSharp/WebBrowserExtensions.cs b/CefSharp/WebBrowserExtensions.cs index 9449dcc76..17f1b2582 100644 --- a/CefSharp/WebBrowserExtensions.cs +++ b/CefSharp/WebBrowserExtensions.cs @@ -644,7 +644,7 @@ namespace CefSharp { ThrowExceptionIfFrameNull(frame); - return frame.EvaluateScriptAsync(script, timeout); + return frame.EvaluateScriptAsync(script, timeout: timeout); } }