JavaFX WebView - getting error messages from JavaScript - webview

I'm playing around with the JavaFX WebView, which shows some simple html pages. I have added a Java class, and want to call methods on that class from JavaScript. This works, I can do something like this in an html page:
function test() {
let todo = manager.getTodo();
document.getElementById("todo-description").innerHTML = todo.getDescription();
}
However, if I misspell the method "getTodo()", e.g. "gettodo()" or whatever, I don't get any error messages. If I just have JavaScript without calling on a Java object, but make some mistake caught at runtime, I don't get errors anywhere. The script just doesn't do anything (which makes sense). I would get an error in the console, in an actual browser.
Is there a way to get runtime errors printed to the Java console, i.e. System.out?
I can log messages, but that's an explicit method call, I have to do.

Related

Parameters in plain html in jsf 2 application

I am making an JSF 2 application. Sometimes I want to do simple things that are easy to do using plain HTML but I get error messages that I don't understand.
For example I sometimes want to write:
Test
But this makes the page break because of "?test1=ee&test2=oo". Having only one parameter seems to be fine but if I try to add more parameters using "&" it complains and says I need to use a ';'-delimiter.
Any explanations why this happens and maybe how to get around it?

Executing Ember.Handlebars templates without using Ember.View

I am using RoR with the ember-rails gem on the server side and Ember.js on the client side.
The on the server side located (Handlebars-)templates are delivered in the Ember.TEMPLATES variable on the client side.
These templates can be used within an Ember.View.
All of this works like a charm, but now the problem:
I have a very small piece of html i want to render.
It is, from my point of view, not worth to create a Ember.View for that.
So what i would like to do something like that..
Ember.TEMPLATES.name_of_the_template(
{
my_text_variable : "my_text"
}
);
This raises an error: TypeError: Cannot read property 'buffer' of undefined
I've looked up the code and i know why this happens (the templates can only be used within a Ember.View or maybe other Ember-Objects).
With Handlebars it is working, but there i have no access to the on the server side stored Handlebars-Templates..
Someone has any suggestions how i can solve this?
Please let me know if you need more information!
Thx!

setting innerHTML in xul

I have in my browser.xul code,what I am tyring to is to fetch data from an html file and to insert it into my div element.
I am trying to use div.innerHTML but I am getting an exception:
Component returned failure code: 0x804e03f7
[nsIDOMNSHTMLElement.innerHTML]
I tried to parse the HTML using Components.interfaces.nsIScriptableUnescapeHTML and to append the parsed html into my div but my problem is that style(attribute and tag) and script isn`t parsed.
First a warning: if your HTML data comes from the web then you are trying to build a security hole into your extension. HTML code from the web should never be trusted (even when coming from your own web server and via HTTPS) and you should really use nsIScriptableUnescapeHTML. Styles should be part of your extension, using styles from the web isn't safe. For more information: https://developer.mozilla.org/En/Displaying_web_content_in_an_extension_without_security_issues
As to your problem, this error code is NS_ERROR_HTMLPARSER_STOPPARSING which seems to mean a parsing error. I guess that you are trying to feed it regular HTML code rather than XHTML (which would be XML-compliant). Either way, a better way to parse XHTML code would be DOMParser, this gives you a document that you can then insert into the right place.
If the point is really to parse HTML code (not XHTML) then you have two options. One is using an <iframe> element and displaying your data there. You can generate a data: URL from your HTML data:
frame.src = "data:text/html;charset=utf-8," + encodeURIComponent(htmlData);
If you don't want to display the data in a frame you will still need a frame (can be hidden) that has an HTML document loaded (can be about:blank). You then use Range.createContextualFragment() to parse your HTML string:
var range = frame.contentDocument.createRange();
range.selectNode(frame.contentDocument.documentElement);
var fragment = range.createContextualFragment(htmlData);
XML documents don't have innerHTML, and nsIScriptableUnescapeHTML is one way to get the html parsed but it's designed for uses where the HTML might not be safe; as you've found out it throws away the script nodes (and a few other things).
There are a couple of alternatives, however. You can use the responseXML property, although this may be suboptimal unless you're receiving XHTML content.
You could also use an iframe. It may seem old-fashioned, but an iframe's job is to take a url (the src property) and render the content it receives, which necessarily means parsing it and building a DOM. In general, when an extension running as chrome does this, it will have to take care not to give the remote content the same chrome privilages. Luckily that's easily managed; just put type="content" on the iframe. However, since you're looking to import the DOM into your XUL document wholesale, you must have already ensured that this remote content will always be safe. You're evidently using an HTTPS connection, and you've taken extra care to verify the identity of the server by making sure it sends the right certificate. You've also verified that the server hasn't been hacked and isn't delivering malicious content.

How should asp.net(mvc) server return error to jquery ajax call to be caught in error callback?

Suppose I have a method in my controller that is called via a jQuery AJAX call. E.g. I'd like to delete a user. When everything goes fine, I return new Content('ok') and exit the method.
What should I do when an error occured? I'd like to indicate it by an appropriate status code, so that my error call back would be called called. Why status code? Read here:
How do you trigger the "error" callback in a jQuery AJAX call using ASP.NET MVC?
However, the approach doesn't work because IIS7 returns it's own message (Bad request) insted of my custom error message.
Besides that there are two other catches:
It has to work with IIS6 as well
IE8 doesn't return the 'Bad request' string. Inside error callback the property request.responseTest is null.
The error callback could look like this:
error: function(request) { alert(request.responseText);}
Setting the Response.StatusCode is the correct thing to do. To fix IIS's "helpful" error handling, set the HttpResponse.TrySkipIisCustomErrors property. You can read more about this here.

Action-specific exception handler HTML in Rails

I've got a bunch of XHR actions in a controller, which return some HTML to insert into the page. If the response is an error, then it puts the output into a special error div. So far, nothing particularly interesting.
However, this general process doesn't work for Rails' exception handling. If I raise an exception in my XHR actions, I get the generic 500 error handler output in my error div, which looks a bit horrific. While I can catch all possible exceptions in my action and render a more appropriate error, I lose the standard exception logging and notification, which sucks.
So, the only solution I can think of is being able to specify a different 500 handler HTML fragment to use for these specific actions, but I'm not finding much. Anyone got any ideas?
You should be able to check for the 500 status code in your javascript handler and display a generic message like "Server Problem". If there are cases where a more specific error message would be useful to an end user in a production environment, you'll have to catch those exceptions with a rescue_from clause. If you really want to prevent the 500 page from showing, you can override the rescue_action_in_public method on your XHR controller.

Resources