Getting JavaScript runtime error: irrationalPath, what does it mean? - javascript

In my MasterPage i'm using the following script
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.3"></script>
And in my application, i have this peace of JavaScript code
document.getElementById(menu_number).src = "<%=HttpContext.Current.Request.ApplicationPath%>/UI/Common/Images/down-arrow.gif";
I also have the Application_AcquireRequestState method below
public void Application_AcquireRequestState(object sender, EventArgs e)
{
// Get http context from the caller.
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
// Check for encrypted query string
string encryptedQueryString = context.Request.QueryString["request"];
try
{
if (!string.IsNullOrEmpty(encryptedQueryString))
{
// Decrypt query strings
string cryptoKey = System.Web.HttpContext.Current.Session["CryptoKey" + System.Web.HttpContext.Current.Session["UNIQUEKEY"]] == null ? HttpContext.Current.Application["CryptoKey"].ToString() : System.Web.HttpContext.Current.Session["CryptoKey" + System.Web.HttpContext.Current.Session["UNIQUEKEY"]].ToString();
string decryptedQueryString = CryptoQueryStringHandler.DecryptQueryStrings(encryptedQueryString, cryptoKey);
context.Server.Transfer(context.Request.AppRelativeCurrentExecutionFilePath + "?" + decryptedQueryString);
}
}
catch (Exception ex)
{
}
}
When document.getElementById(menu_number).src = "<%=HttpContext.Current.Request.ApplicationPath%>/UI/Common/Images/down-arrow.gif"; is being executed, it throws the below error in IE 11.
JavaScript runtime error: irrationalPath
It also throws an exception in method "Application_AcquireRequestState" but i'm not able to get the exception details. When i put a try -- catch in the method "Application_AcquireRequestState", the exception inner message being returned is
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
I'm finding it hard to debug this. The above line of JavaScript executes successfully on the initial page load but throws that error when i'm clicking particular hyperlinks after page load.
What could be the most likely causes of JavaScript error: irrationalPath?
And what does "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." actually mean?
Any suggestions on how i can effectively troubleshot this?
I have already seen observed that the IrrationalPath exception is defined in the javascript file at http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.3

The most likely cause of the JavaScript error: irrationalPath error probably has nothing to do with any of the code you posted in the question. It's a dojo error that is usually seen when there's a problem with the dojo loader. It probably has something to do with the paths or pacakges setup in dojoConfig. See here for more info.
The other error you are getting is a .NET error. I can't be certain without seeing more of your code but this Microsoft support article is a good starting place for troubleshooting that erroor

Have you tried to make the HttpContext.Current.Request.ApplicationPath as String in your js code (delimited with two quotes).
js code become :
document.getElementById(menu_number).src = <%="'"+HttpContext.Current.Request.ApplicationPath+"'"%>+"/UI/Common/Images/down-arrow.gif";

Related

How to throw a javascript error during runtime via browser (Chrome)?

My objective: Test out my error handling functionality.
Temporary solution: Have a custom route: /error, which contains code which purposefully produces fatal error.
var a = undefined;
a.b.c // Breaks.
The above works, but I can't use it to test production site as the page is not required.
I was looking for a way to test it via the browser. I tried simply adding"
throw new Error("Custom error thrown here") to the console. That doesn't actually break it during runtime.
I tried adding a break point and adding the same code: throw new Error("Custom error thrown here"). That didn't work either.
Any other easier ways to do this rather than the above?
I was looking for a way where I can do it via browser only.
Thanks.
You did not clearly mention how and where the error should be thrown. I will assume that you can use a modified copy of your JavaScript file to throw errors. The modified file will reside on your computer and only be used when you're using Chrome developer tools. This feature is called Local Overrides. The steps are as follows:
Open the webpage
Open Chrome developer tools for that webpage
In Sources panel go to Overrides tab
Click Select folder for overrides and choose a folder on your computer
A warning appears on the webpage which reads "DevTools requests full access to ..." which you must allow
In Sources panel go to Page tab
Locate the file in which you need to inject the "throw error" code
Right click and choose Save for overrides
Now you can edit the copy of the file on your computer or from within developer tools. Insert the code that produces the error at the desired location. When you reload the page with developer tools open, Chrome will load the local copy of the JavaScript file and throw the error. The error thrown that way will contain the context from where it originated e.g. call stack. If the developer tools are closed then live copy will be used.
If I got your question right, this is How you can do it from the console:
var script_tag = document.createElement('script');
script_tag.type = 'text/javascript';
script_tag.text = 'throw new Error("Custom error thrown here")';
document.body.appendChild(script_tag);
Or if you want you can trigger it on click:
var script_tag = document.createElement('script');
script_tag.type = 'text/javascript';
script_tag.text = 'window.document.onclick = function() { throw new Error("Custom error thrown here")}';
document.body.appendChild(script_tag);
And then you click anywhere on the page, to throw the error;
I would use the exec function which actually takes string and runs the code within at compile time.
exec('a.b.c')
You won't be able to throw an error inside your application from the console, since you are out of scope of the app.
Having said that, one slightly awkward way you could do this is by adding a breakpoint at the start of the javascript file.
Reload the page and your app will pause at the breakpoint - you can then modify the code as you need - like adding a throw new Error("something...") - and save your edits.
Then allow the code to run and you will see your error.
A downside is if you reload the changes will be gone, but I believe it's as close as you can get to modifying code at runtime.
Add this code to your production code
window.addEventListener('err', () => {
throw new Error('break it');
})
and when you want to create an error simply
dispatchEvent(new Event('err'))
in the console
You can use a global variable, which is accessible from your app and from debug console.
if (window.shouldThrow) {
throw new Error("Custom error thrown here");
}
This way you can turn on/off the exception throwing using the window.shouldThrow variable.
Try this way to catch error detail on run time
try
{
var a = undefined;
a.b.c // Breaks.
}
catch ( e )
{
alert("Error: " + e.description );
}

HtmlUnit JavaScript Issue on page load - Cannot find function

I'm crawling website secured with Cloudflare and sometimes getting an error due to redirection to page with ReCapcha, the page cannot be even loaded due to some javascript error. The code is failing on #getPage method and i have no idea why.
Here is the code works fine for normal pages, but fails on confirmation page:
final WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setJavaScriptEnabled(true);
final HtmlPage page = webClient.getPage("https://mydummy.site");
webClient.waitForBackgroundJavaScript(10000);
int waitForBackgroundJavaScript = webClient.waitForBackgroundJavaScript(200);
int loopCount = 0;
while (waitForBackgroundJavaScript > 0 && loopCount < 2) {
++loopCount;
waitForBackgroundJavaScript = webClient.waitForBackgroundJavaScript(200);
if (waitForBackgroundJavaScript == 0) {
break;
}
}
Logs:
java.lang.RuntimeException: com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function start in object [object MessagePort]. (https://www.gstatic.com/recaptcha/api2/v1536705955372/recaptcha__en.js#249) (https://www.gstatic.com/recaptcha/api2/v1536705955372/recaptcha__en.js#253)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:305)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:539)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:399)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:316)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:467)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:449)
at Main.htmlUnit(Main.java:156)
at Main.main(Main.java:43)
Caused by: com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function start in object [object MessagePort]. (https://www.gstatic.com/recaptcha/api2/v1536705955372/recaptcha__en.js#249) (https://www.gstatic.com/recaptcha/api2/v1536705955372/recaptcha__en.js#253)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:892)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:616)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:532)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:772)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:748)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:104)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:992)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:371)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:246)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:298)
We have been struggling with this issue as well. Our test suite ran perfectly until late 2018 when this issue broke all of our logins. I believe Google has put this in deliberately to break automated attempts to break captchas, because solving one part of this seems to only lead to another problem. Both loading the page and submitting the page causes issues, even if you tell HtmlUnitDriver to ignore all JavaScript errors.
I have tried several options at this point. If you use the Google specified test site key, then the errors go away. So if you have full server-side control of how that site key is generated, you are OK. Remember to ensure that the test site key shows up again on validation errors and all similar use cases, otherwise you will get that error.
(Unfortunately for us, our login page is plain JSP and so implementing this is a headache unless we want to change the URL everywhere. Still debating what to do, for right now we do have a workable if ugly solution that involves some conditional logic on the page and catching JavaScript exceptions at other points in the test code.)

Swift JavaScriptCore not working with large files?

https://github.com/gg2001/monero/blob/master/monero/NewWallet.js
I have a js file that is quite large 6000 lines and JavaScript core does not seem to be able to retrieve variable values whereas running the same file in any web browser works fine for me. When I try to retrieve the value of a variable it shows up as undefined, but when I use a js console in a browswer it shows up fine. I am speculating that this is due to the size of the file because when I put
var helloWorld = "Hello World";
in the front of the js file this swift code can retrieve it
func helloWorld() {
if let variableHelloWorld = self.jsContext.objectForKeyedSubscript("helloWorld") {
print(variableHelloWorld.toString())
}
}
but when I put it at the end it cannot.
Normally this indicates a parsing error. Try adding an error handler to self.jsContext before calling objectForKeyedSubscript() and see if it outputs anything insightful.
self.jsContext.exceptionHandler = { context, exception in
print("JS Error: \(exception?.description ?? "unknown error")")
}
Although your JS code may be valid in a browser console, iOS Safari doesn't support as many Javascript features as newer browsers.
I did see a line in your JS source code beginning with just a semicolon (followed immediately by (function). I wonder if the parser might complain about an empty line without a statement..? Maybe nothing, though.

What is causing this link to error saying "is not a valid virtual path"?

I have some code that works locally but when I put it up live, it causes an error. Not just an error, but the page doesn't load and I get a huge error page that states:
'/Clients/CMCDFMIS/gateway.htm?p=Dallas' is not a valid virtual path.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Web.HttpException:
'/Clients/CMCDFMIS/gateway.htm?p=Dallas' is not a valid virtual path.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): '/Clients/CMCDFMIS/gateway.htm?p=Dallas'
is not a valid virtual path.] System.Web.VirtualPath.Create(String
virtualPath, VirtualPathOptions options) +8877083
System.Web.VirtualPath.Create(String virtualPath) +9
System.Web.UI.PageParser.GetCompiledPageInstance(String virtualPath,
String inputFile, HttpContext context) +163
AtgHttpHandler.AtgHttpHandler.ProcessRequest(HttpContext context) +804
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Version Information: Microsoft .NET Framework Version:2.0.50727.4062;
ASP.NET Version:2.0.50727.5692
HTML:
<a href="../gateway.htm?p=Dallas">
What I am doing with it is in JavaScript:
urlExtract = location.search
foundExtract = urlExtract.split("=")[1];
if(foundExtract == "Dallas"){
//do something
}
else if(foundExtract == "Legacy"){
//do something
}
I don't think it is really getting to the JavaScript though. I have used this urlextract code on another site years and years ago so I am not sure why in this case it is giving me problems?

Why does ExternalInterface breaks when I pass parameter with JSON like string?

I have a very odd problem with Flash 10 and ExternalInterface. I am currently using a homemade bridge to use RTMFP with Javascript and whenever I try to pass data that contains JSON, I get a wierd Javascript error that comes from Flash :
missing ) after argument list
try { __flash__toXML(Flash.Utilities.A..."")) ; } catch (e) { "<undefined/>"; }
It's impossible to get more information since this come from Flash and it's not bound to any Javascript file.
To reproduce this problem you can use this script :
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.external.ExternalInterface;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var test:String;
test = "\"\\\"\"";
ExternalInterface.call("console.log", test);
}
}
}
What can I do to avoid this problem and is it a known problem ?
This is apparently a known issue and it doesn't seems like Adobe is going to fix it anytime soon.
I found a detailled explaination of this problem and basicly the issue seems to be that Flash doesn't handle the \ and the & properly which can lead to javascript error or data corruption during the transfer from Flash to javascript.
What Flash attempts to do when you transfer data from Flash to JS is to execute the following thing :
try {
__flash__toXML(yourJavascriptFunction("[DATA]")) ;
} catch (e) { "<undefined/>"; }
The problem is that it puts your data raw and it doesn't escape the backslash at all. If your string contains only \ and you want to call console.log on it, it will try to do the following thing :
try {
__flash__toXML(console.log("\")) ;
} catch (e) { "<undefined/>"; }
As you can see this is invalid javascript. It will throws an error in your Javascript console and it will never call console.log.
The solution is to either ducktape Flash behavior or do some nasty hack to get around it.
To ducktape Flash buggyness you can escape the blackslash before you transfer them. This solution will work for now, but when Flash will fix it (most probably not in a near future, if you consider that this bug is known for more than 4 years), it will break your application.
The other possibility is to url encode the character that Flash doesn't handle well (\, ", &) and to decode them on the other side.
Flash :
data = data.split("%").join("%25")
.split("\\").join("%5c")
.split("\"").join("%22")
.split("&").join("%26");
Javascript :
data = data.replace(/%22/g, "\"")
.replace(/%5c/g, "\\")
.replace(/%26/g, "&")
.replace(/%25/g, "%");
It's ugly, but it works.
Admittedly this wouldn't work directly for output to the console in Firebug, but for most other applications (i.e. sending a potentially 'invalid' string to Javascript), escape and unescape should work just fine:
AS3:
var testString:String = "\"\\\"\"";
ExternalInterface.call("showString", escape(testString));
And then in Javascript:
function showString(msg) {
console.log(unescape(msg));
document.getElementById('messagebox').innerHTML = unescape(msg);
}
<div id="messagebox"></div>

Categories

Resources