ClearScript apparently can't find a function added dynamically to the window object.
In a regular html file, I can call "var passwordAnalysis = zxcvbn($(this).val(), penalties);" just fine.
However, I am trying to execute https://raw.github.com/lowe/zxcvbn/master/zxcvbn.js inside a C# project.
I always get the exception:
ScriptEngineException: TypeError: Method or property not found.
I suspect it is because the zxcvbn method is added dynamically.
C# Code is as follows:
using Microsoft.ClearScript;
using Microsoft.ClearScript.V8;
public class RunScripts
{
public void GetPasswordStrength(string password, string[] penalties)
{
using (var engine = new V8ScriptEngine())
{
engine.Execute(ZxcvbnScript);
var result = engine.Script.zxcvbn(password, penalties);
//or
var result = engine.Script.zxcvbn(password);
//or
var result = engine.Script.zxcvbn(password);
}
}
}
Comments: Ok, I don't think this is actually a problem with ClearScript - it occurs to me that this is probably "just" a javascript engine, and does not include an implementation of the DOM. I was actually able to run the script like I wanted with a very simple modification: public class JsWindow { public object zxcvbn { get; set; } } public class RunScripts { using (var engine = new V8ScriptEngine()) { engine.AddHostObject("window", HostItemFlags.GlobalMembers, new JsWindow()); engine.Execute(ZxcvbnScript); var result = engine.Script.zxcvbn(password, penalties); } }
In a regular html file, I can call "var passwordAnalysis = zxcvbn($(this).val(), penalties);" just fine.
However, I am trying to execute https://raw.github.com/lowe/zxcvbn/master/zxcvbn.js inside a C# project.
I always get the exception:
ScriptEngineException: TypeError: Method or property not found.
I suspect it is because the zxcvbn method is added dynamically.
C# Code is as follows:
using Microsoft.ClearScript;
using Microsoft.ClearScript.V8;
public class RunScripts
{
public void GetPasswordStrength(string password, string[] penalties)
{
using (var engine = new V8ScriptEngine())
{
engine.Execute(ZxcvbnScript);
var result = engine.Script.zxcvbn(password, penalties);
//or
var result = engine.Script.zxcvbn(password);
//or
var result = engine.Script.zxcvbn(password);
}
}
}
Comments: Ok, I don't think this is actually a problem with ClearScript - it occurs to me that this is probably "just" a javascript engine, and does not include an implementation of the DOM. I was actually able to run the script like I wanted with a very simple modification: public class JsWindow { public object zxcvbn { get; set; } } public class RunScripts { using (var engine = new V8ScriptEngine()) { engine.AddHostObject("window", HostItemFlags.GlobalMembers, new JsWindow()); engine.Execute(ZxcvbnScript); var result = engine.Script.zxcvbn(password, penalties); } }