wxWebView and JavaScript - javascript

I am trying to write a program in C++ and wxWidgets that accesses YouTube and start the video with JavaScript.
It uses the YouTube JavaScript API, documentation for which is found here.
I wrote the following piece of code to play ‘O, Canada’, specifically the one here.
wxWebView *webview = wxWebView::New(this, wxID_ANY, "http://www.youtube.com/watch?v=zwDvF0NtgdU");
webview->RunScript("function onYouTubePlayerReady(playerId) {document.getElementById('watch-player').playVideo();}");
Running the above code fails to fulfill its intended purpose, giving me the following error and a crash:
....\src\msw\wxwebview_ie.cpp(762): "assert "document" failed in wxWebViewIE::GetDocument().
I know that my code successfully LOADS the page, but running the JavaScript (the RunScript() function) seems to result in the error.
I am using wxWidgets 2.9.3 on Windows.

This should have been fixed in revision 71030 which is more recent than the 2.9.3 build that you are using. You can get the updated code either through SVN or a daily snapshot. If that still doesn't fix it please file a bug on the wxWidgets Trac.

The problem is actually because I call the JavaScript too early, before the page is loaded. If I call it a bit later, it works.

Related

Run DOM-based Javascript from command line

I have some Javascript that is interacting with the DOM from a website.
document.location.href="https://www.example.com";
It works well from Chrome console, but I would like to run that code from the command line. How can I do it? NodeJS gives "document is not defined" error.
In order to use command line to inject Javascript code in a browser's DOM you actually need...a browser that runs Javascript code ad has a DOM.
You can go with something like Selenium or rely on a bridged library like https://github.com/prasmussen/chrome-cli
What you are looking for is called jsdom! https://github.com/jsdom/jsdom
When you run the code from browser the DOM api is included, so your code excutes accordingly and finds the the location object with information about the current document your on. When you try to run it from command line using node.js the DOM api is not included which is why it gives you "document is not defined" error. Node.js is for excuting server side js code.

Debugging JavaScript in client

I'm facing an issue while debugging my application. Following is the architecture:
Server: Java (Servlet)
Client: React+D3
Problem: Whenever, I change some react or d3 code and if an error occurs then it just shows me that some react (or d3) error has occurred but never tells me which function the error occurred (as seen in snapshot). Now, I know that simply debugging it by having the information like variable name and searching where I defined that variable. However, situation becomes tough when I use same object multiple times (say window) and had made several changes in the code. In this case, a specific line number where the error occured can be handy and quick. Let me know if I'm missing some basics about debugging such applications?
EDIT1:
1. In the snapshot, http://localhost:8080/..../Server Server is the main servlet application, kind of launchpad, which triggers several other react-based js files.
2. The mentioned ReferenceError is inside a function updateWindow() but the console never mentions this (and that's my problem).
PS: I'm using Eclipse tomcat on server-side
I think there's no straight forward solution to this problem. So, I'll post the method that worked for me with few additional points:
Problem: It doesn't gives a nice error trace like standard Java application, probably because it mixes with JavaScript code.
At every line of the error trace, line:column specifies the error line. I used this as a reference and started manual debugging from where my application launches i.e. Server.java and look where I defined the createChart() in the JS file and drill-down until I found the referenced variable.
In case of ReactJS' error (an error after resolving reference issue), I debugged it with normal react.js (not minified version react.min.js) so that it shows me exact line of error. Minified version is cluttered and is useless while debugging.
PS: If someone has better answer I'll edit this in future.

Debug Javascript in Android WebView from same app

I'm experimenting with a simple Javascript debugger for a WebView. I'd like to debug/control/inspect how some Javascript code is being executed inside my WebView.
I haven't found any solution other than using the WebChromeClient to receive the console messages.
Since I have access to the Javascript code I can add instrumentation code: a console.log call before each line, with a special message (e.g. "debugging line 3") that tells which lines have been executed.
It's quite rudimentary so I wonder if there's any better solution. It would be great if I could use the debugger statement to really control execution flow.
This is what I have been doing if I want to console.log() anything directly on the mobile browser so that debugging can be done on the actual device and not in emulator or similar...
I made JS debugger plugin and here is what it have:
it creates an absolutely positioned HTML element that is placed on top of the content and is semi transparent.
I made the JS logic that actually simulates what console.log() does and print out all desired information in mentioned HTML element
once plugin was done I simply used MoibileDebugger.log('what ever'); instead of console.log('what ever');
My code is still not published publicly but will do that soon, so that anyone can benefit from using it...
In any case this plugin can be made very quickly by anyone who is good in JS.

Export Flash parameters to JavaScript

I'm trying to pass parameters from Flash (as 3.0) to JavaScript.
Tried all methods I found in via. Google, as:
ExternalInterface.addCallback ("fonts", recieveFromJS);
Always one and the same problem; when I try to call the fonts () swfobject, JavaScript gives the error that the method doesn't exist.
Assuming your javascript code does not have a syntax error somewhere, this usually happens because of jquery (or some other js bundle) is stepping on your code. Try using a test page with just the javascript you need, removing all other code and header entries. If it works, then add scripts and links back, one at a time, and you will find which code is breaking it. If it does not work even in your test page, then you have a code/syntax/logic problem with the snippet of code you are working with. If you still have a problem with a code snippet, post it here and I or someone will surely help debug it for you.

Uncaught TypeError: Cannot call method 'each' of undefined

I have this error while trying to run mediaelement player.
The error is reported at mediaelement-and-player.min.js:44.
Edit: My apologies, I posted this from the mediaelementjs.com Support website.
I was trying to use mediaelement.js to play audio on my website.
Edit 8/2: The interesting thing is that when i load the full mediaelement-and-player.js instead of the minified version, it works fine.
I just dealt with this same issue while trying to use the Drupal module, http://drupal.org/project/mediaelement.
Turns out that a core Drupal javascript file, drupal.js, was calling jQuery.noConflict() which removes the $ variable from being defined in the global scope, hence bringing this bug in mediaelement-and-player.js to light.
This was reported in the issue queue for the mediaelement project and it looks like the fix just got committed: https://github.com/johndyer/mediaelement/pull/570
Most likely you have not loaded the jquery library into your script.
You have to reference the library (a js file) from within the header of your page via url. The url can point to a copy pf jquery you keep local or to a public site.

Categories