Is it possible to detect parse errors in an HTML submitted to a WebView, using -loadHTMLString:baseURL:?
Is there a method that can be called when parsing errors occur?
The only possible delegate callback might be this, but I don't think it will give you what you're looking for (it's almost certainly network errors). A quick perusal through the list of possible NSError codes (near the bottom), don't have anything that might relate to your error. It seems you're out of luck here.
If you need to deal with parsing, then you're going to be using a different HTML renderer, such as WebKit or Blink. There are a few frameworks for building native apps that use the WebKit or Blink renderer. One of the most active is called Node-Webkit. While I can't say for absolute certainty that it will expose the parsing that you're looking for, the odds are much higher.
Some others that are similar are appJS and CEF. I like Node-Webkit because it's very simple to set up while also being fairly mature and in rapid development. If it doesn't give you what you're looking for, one of those others might.
Related
I'm writing a game in C++ using the SDL framework, and want to create my game's GUI using HTML/CSS. I've looked into frameworks such as Awesomium, however I'm turned off by the fact that it's not open source. I want to create my own implementation of a similar idea.
However, I can find almost no documentation on actually using WebKit in this manner. The closest I can find is this Apple Developer guide to using WebKit but it's targeted at MacOS-specific applications written in Objective-C. It makes mention of a "Webkit C Reference" toward the bottom of the page, but I cannot find this actual document anywhere. Additionally, I've read the resources on the WebKit Wiki as well as prior StackOverflow questions on the same topic, but I haven't been able to find anything in the way of direct, clear documentation on embedding WebKit in a C++ program.
Does this documentation exist somewhere? What is the best resource for documentation on embedding WebKit within a C++ application?
I'm not really sure about this, but when I read about "c++" and "html/css". QT comes to my mind. Maybe you want to check it out.
I have an iOS app where I read the data from the website in a UIWebView which is hidden from the user (don't worry its my own website), parse the data from the resulting HTML, read specific info and put it into NSArrays to display in UITable. All is well and good and works in iOS.
- (void)webViewDidFinishLoad:(UIWebView *)webView2
{
NSLog(#"webViewDidFinishLoad ...");
NSString *htmlSourceCodeStr = [webView2 stringByEvaluatingJavaScriptFromString:#"document.documentElement.outerHTML"];
}
I was thinking of porting the same app to tvOS. Surprise Surprise UIWebView isn't available in tvOS.
Is there a way for me to load / Fetch website data somehow in tvOS, parse and read the resulting HTML? Is that even possible?
Just make the HTTP request directly using NSURLSession. You'll get the HTML back as NSData and can parse it from there just like before. You should probably do the same in your iOS app: if you're not going to show the HTML to the user then there's no point in using something as heavyweight as a web view.
To answer your question, no (kind of), it is not possible at the moment. The link you posted pretty much answered your question - there may be a way using private APIs or using UIWebViews (maybe), but Apple would never allow it to be published. Not only that, but WebKit isn't available either. This pretty much sums it up:
Companies hoping to leverage a universal HTML5/CSS/JS-based UI for multiple platforms may no longer find this option viable. They will need to rethink their strategy for providing a cohesive branded experience on multiple platforms while still writing native apps for those platforms. That’s not to say that someone wouldn’t be able to try compiling WebKit and creating their own view within to render HTML. Certainly there are companies with the manpower and resources to do this. I’m not certain those apps wouldn’t get rejected, though.
Very sorry I couldn't give you the answer you were looking for. Good luck :)
Sources
https://developer.apple.com/library/tvos/releasenotes/General/tvOS90APIDiffs/index.html
https://medium.com/bpxl-craft/apple-tv-a-world-without-webkit-5c428a64a6dd#.s2h3xvsx6
Web app in tvOS
http://www.idownloadblog.com/2015/11/06/apple-tv-browser-hack/
Problem
So we have quite a big project with lots of different Partial Views and a client side data binding framework (Knockout.js in our case).
One of the more problemtic parts is that is getting harder and harder to figure out which partial view is rendering an element that I see on my page.
So I need to debug this particular DIV. Okay, where do I find it?
Usually I try to find a very specific class or ID close by this element and do a search through the whole platform - far from ideal.
Question
So I was thinking about the following; tagging all elements (in debug mode) with the source file where they have been generated.
Right now I'm thinking about something like a precompiler that adds a data-source="" to every element. I might refer to an ID within a dictionary to prevent repeating all the long filenames.
Before I'm reinventing the wheel:
is there already something similar?
are there better alternatives?
We're using ASP.NET MVC, but any hints to how other platforms do this are perfect too.
If you are using Visual Studio, I highly recommend the Web Essentials extension. Among many great features, it has one called "Inspect Mode", part of the larger "Browser Link" feature, that does exactly what you are looking for; it identifies the file that a particular DOM element came from. It might be worth a shot if that option is open to you.
#Dirk, as per my understanding your issue is to easily identify the element/view. Adding data-source can be an option but before that have a look at this link
Editing Styles and DOM - Chrome Dev Tools
This page has many demonstrations which might be helpful to your problem. Furthermore, I do agree with Kevin suggestion.
Assuming I already have valid code, is there a tool or plugin that I can use to evaluate my website code and highlight areas where different browsers could potentially display the code differently? I am aware of websites like browsershots and I have VMs to test, but I'm wondering if there is something to shortcut the process by looking at the code and warning of well known cross-browser compatibility red flags.
For example, when using CSS which is not universally supported yet. The following is valid CSS 2.1:
display: run-in;
Validators which are aware of CSS 2.1 will pass it with flying colors, but really, a red flag should be thrown, indicating that it does not work in Firefox 3. On the other hand,
border-radius: 10px;
is actually pretty well supported in updated browsers, even though it is CSS3.
This is new in Javascript, but is also passed by validators:
getElementsByClassName();
but it would be better if a warning popped up notifying me it won't work in IE8.
Another example is well known rendering bugs, which can be triggered by weird (valid) situations. I understand there is no replacement for opening up the website in every single browser on every system to really see how it works, but I am just wondering if there is some tool that can help check that I'm writing interoperable code as I go, so that I can test more frequently in the development process and spend less time working out bugs later.
Unfortunately, the answer is no.
I once started looking into creating a tool exactly as you describe. The reality is that most libraries like jQuery actually make use of browser incompatibilities and different interpretations of standards (or ignoring the standards).
So, if you're using any of the standard libraries then you'd receive tons of warnings and actually get very little out of it. The amount of spam simply will shadow the actual bug you might have introduced.
What matters more is whether the incompatibilty actually affects the end result. Hence we went for what-you-see-is-what-you-test method instead of static code analysis.
i noticed a very strange way of naming classes in G+ and gmail..
example: a-b-h-Jb a-b-Rf-dB a-Rf-dB d-s-r (see G+'s code for yourself!)
who the hell does that? impossible to keep track of what you did in future.. same for gmail.
it is a known way of doing css that i am unfamiliar with? is it OOCSS? if a googler is reading this, can you please explain? Or if you are not the one who wrote the code, then please share your thoughts or prove that i am a dumb ass and don't know about a fairly common css naming 'good practice' (can i even call it that?)
Google uses something called the Google Web Toolkit (or simply GWT) to compile Java "applications" into their Javascript/HTML/CSS counterparts. GWT was used for GMail and Google Wave and my assumption is that it was also used for G+.
The GWT "compiler" (CS purists would never call GWT a compiler but the term fits) programatically names Javascript functions, CSS classes, HTML form IDs, etc. so they are almost never something legible.
At a guess, they probably have everything written out nicely in full at some point, and then put it through some program to compress it (reduce the length of variables). This reduces readability but also reduces file size, improving load times in theory.