diff --git a/CefSharp/IJavascriptObjectRepository.cs b/CefSharp/IJavascriptObjectRepository.cs index cf9f1c152..8ec5b3b58 100644 --- a/CefSharp/IJavascriptObjectRepository.cs +++ b/CefSharp/IJavascriptObjectRepository.cs @@ -35,6 +35,13 @@ namespace CefSharp /// and other advanced options though this class. void Register(string name, object objectToBind, bool isAsync = false, BindingOptions options = null); /// + /// UnRegister a bound object from the repository. If you unregister an object that is currently + /// bound in JavaScript then the method/property calls will fail. + /// + /// object name + /// returns true if the object was successfully unbound otherwise false. + bool UnRegister(string name); + /// /// Has bound objects /// bool HasBoundObjects { get; } diff --git a/CefSharp/Internals/JavascriptObjectRepository.cs b/CefSharp/Internals/JavascriptObjectRepository.cs index 6169c2047..e9981e41a 100644 --- a/CefSharp/Internals/JavascriptObjectRepository.cs +++ b/CefSharp/Internals/JavascriptObjectRepository.cs @@ -160,6 +160,21 @@ namespace CefSharp.Internals AnalyseObjectForBinding(jsObject, analyseMethods: true, analyseProperties: !isAsync, readPropertyValue: false, camelCaseJavascriptNames: camelCaseJavascriptNames); } + public bool UnRegister(string name) + { + foreach (var kvp in objects) + { + if(string.Equals(kvp.Value.Name, name, StringComparison.OrdinalIgnoreCase)) + { + objects.Remove(kvp.Key); + + return true; + } + } + + return false; + } + internal bool TryCallMethod(long objectId, string name, object[] parameters, out object result, out string exception) { exception = "";