I have developed a Chrome extension and it captures some data in a webpage.
My ultimate goal is to pass this final result to my Java Application.
I have following few options in my mind, but I was not able to find any resources for them yet.
Access the localStorage externally.
Run Chrome browser through the Java app, So I guess we have the control of its data.
If no API found, write the result to a file and access it from the
Java App.
Is there any API to achieve any of the first 2 options? Or any other interface other than the file system?
I checked with berkelium and The Chromium Embedded Framework. But they are just chrome wrappers, and we cannot run a chrome instance from it.
Edit
For the 2nd option I tried with Selenium Webdriver, but I think it hasn't any method to access the localStorage.
It sounds like you are looking for Native Messaging, which allows communication between a Chrome Extension and a native application (e.g. a Java Desktop Application).
There are plenty of question here on SO regarding the implementation of Native Messaging and there is, also, the "official" example.
I suggest the above solution, but if your application will heavily interact with the extension (and you feel like reverse engineering) there is the open-source **[NetBeans Connector Chrome Extension][3]**, which uses a different approach (Sockets or WebSockets - I am not sure).
Take a look at **[this answer][4]** for info on how to get at the sources.
Is there a limitation preventing you from exposing a REST API with your java application?
Related
I built a large JAVA web application using SPRING & MongoDB,
In some scenarios, I want to allow my users to upload their own code, and the application will run it later on when necessary.
I called this operation "Plugin framework", the plugin is the user's code of course which I prefer to be in NodeJS for now.
There is any recommended / known architecture for that purpose?
I've read about pf4j and senecajs, but they quite different from my needs.
Thanks!
You loose complete control over code running on node. The uploaded code can access network, files, database, you name it. That is not a good plan.
I suggest to work with the embedded JS module in Java, called rhino. Here, you define which environment the code can access.
You find samples of using the scripting in Java here http://docs.oracle.com/javase/7/docs/technotes/guides/scripting/programmer_guide/index.html for jdk7, the Javadocs https://docs.oracle.com/javase/8/docs/api/javax/script/ScriptEngine.html and here some info on Java8 changes http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html
UPDATE:
On the comment below, you state that you think you are safe, if the code runs on the other server. Actually, the problem is still the same. Just it won't hit your application's server but the JS code server.
My advice stands. Implement a JS execution service using the built-in Javascript engine (Rhino or Nashorn) and restrict the running JS to a sandbox, you control the script's reach out of the box through carefully implemented env-access methods. It is actually pretty easy to get started, no more complicated than implementing a remote javascript implementation engine on top of node...
I would like to replace Java Applet which currently needs to use client's resources, i.e. external readers, and to communicate with a server via socket.
Reason:
1. I have thousands of client machines using this Java Applet program, and most of them are running out-dated JRE. When the Java Applet program is updated / added new features, all client machines will need updating the latest JRE.
Expected Solution:
The Java Applet program would be expected to be replaced by a web-based application, which allows to compile and run source code at client's side such that the new web-based application could still use client's resources and communicate with server via socket.
Can I use JavaScript to achieve it?
I would very appreciate your help/suggestion for this problem. Thank you!
JavaScript is a scripting language that gets evaluated in the browser.
I would not describe it as compiling and running but yes, it does mean you can run code in the client and is commonly used to create applications that run in the browser.
There's a staggering amount of frameworks that you can use to write your application. Take a look at the TodoMVC site to see the same TODO app created using several different frameworks.
If you come from Java applets, GWT may be interesting to look at.
If you wish to let the JavaScript client listen for messages from the server, take a look at websockets.
The smart card reader is going to be a problem, though!
See Architectures to access Smart Card from a generic browser? Or: How to bridge the gap from browser to PC/SC stack?
By the way:
The real issue with outdated JREs is not that your code will not run on old JREs, you can create perfectly fine applets using java 1.4 or java 5. Any libraries you may need you can deploy alongside your applet. The pain is a security problem. Anything but the latest version Java plugin is getting actively exploited and puts the user at risk. Occasionally, even the latest version is not safe.
try socket.io
I think this is the latest technology you can use to communicate with client browsers. it support the latest browsers and mobile browsers too.
hope this will help you.
Javascript has become very powerful with HTML 5.0. Here is a list of new elements that you can use to access all kinds of resources, including local files, audio, video, GPU rendering (canvas + WebGL) and GPU compute (WebCL). Here are even more things you can do, including database connections and networking. You can even create offline Javascript applications.
jQuery and jQuery layout make robust GUI development a lot easier. Rich tool suites, such as Google Closure offer optimization and a compiler for improving performance and detecting obvious mistakes early in the development process.
W3 offers useful stats for making an informed decision on how many users on average have access to which features. Note that the most annoying guy in that list arguably is IE8 due to it's lack of proper HTML 5.0 support.
In case you want to stick with Java, then one alternative would be to use my http://bck2brwsr.apidesign.org project. It's goal is to create small Java that can run in 100% of modern browsers without any plugin installed.
There are Java bindings to HTML (via knockout - one of the four most popular frameworks for HTML5) and that is why one can code whole business logic in Java and just render it via HTML. Should be enough to replace most of the applet UI.
In addition to that there is an experimental API to render on HTML canvas. People use it to write Java games that run in a pure browser.
There is a simple way to communicate with server via JSON REST API or via WebSockets. A live example is here.
Is it possible to integrate Java, Python, or Objective C directly with the Firefox browser? In particular to do "real", native tasks such as writing files or connecting to a local database, or better yet, directly calling systems level code ?
Notably, there is a post on native code execution, somewhat slanted towards windows, elsewhere on StackOverflow: Firefox extension: native code execution?
In particular to do "real", native tasks such as writing files or
connecting to a local database, or better yet, directly calling
systems level code ?
You don't need an extra language for that, Firefox extensions can do it already:
Writing files
Connecting to a local SQLite database
Calling system libraries directly
I would recommend against attempting to write the extension in anything other than JavaScript: while there are several possibilities they create a lot more trouble than they are worth. If anything, you could create a native library and call it from your JavaScript code via js-ctypes (see link above).
A "signed" Java applet, given the correct permissions and approved by the user, can run in the browser context and have access to files or databases. However, Java applets in the browser are almost never used today (I've had Java disabled in my browser for years).
Microsoft browsers offer ActiveX, which is a way of running native code in the browser, but I don't know whether anybody uses that today either.
Google's nativeclient is another method of running native code, but only works with Google browsers at this time. Not sure whether that allows direct access to files at all.
PythonExt brings Python support to Firefox:
http://code.google.com/p/pythonext/
I'm not sure how quickly they update it for Firefox's rapid releases, and you do need to install an extension, and then it will only work in a trusted context (i.e. an extension you right yourself)
Alternatively you could build Windows 8 Metro style apps that let you use web technologies and native code together:
http://channel9.msdn.com/posts/Raman-Sharma-Building-Metro-Style-Apps-with-C-and-JavaScript
http://code.msdn.microsoft.com/Hybrid-JavaScript-and-C-e6dc77fa
I am learning to build Chrome extension and I have an idea to build something which requires complex computation (using many java libraries) which seems hard to be implemented by JavaScript.
A general architecture I have in mind is:
Chrome Extension (GE) extracts HTML elements and feeds HTML elements to Java application as input. Java application does the complex computation, and then feedback the results to GE. GE finally renders the results into the browser.
Does anyone know is this feasible? Does this have to involve a server architecture? Could you also refer me to some further information?
Note: It is a Java application, hopefully you can give me some Java specific answers.
Thanks in advance.
You would need to create java web application running on server (which can be accessed via URL) which you will be communicating with through ajax requests. Chrome extension (or any other js app) doesn't care what's running on server - java, php, or something else. It just sends HTTP POST/GET request to provided url and receives response back.
If you are asking if you can pack some java into your extension then the answer is no. You can pack some C++ though.
I want to write a firefox plugin which will communicate with a java application.
The plugin will have to notify the java application of the web page/ url being loaded.
The java application will take care of the rest.
Any help or pointers will be much appreciated.
I have authored a couple Firefox plugins with precisely this requirement.
One strategy is to use the JavaScript-to-Java bridge in Firefox, which permits the use of Java RMI. I found this approach slow and unstable, and the multithreading is painful.
My current solution is to open a localhost socket and use a textual protocol to communicate. See the XULPlanet developer guide on sockets for how to open and read/write with sockets in Firefox JavaScript, and there's a Sun tutorial on sockets in Java.
The source code to one plugin I wrote (for Firefox and Eclipse) is available under the X11 aka MIT license: Firedoclipse source. Under the lib directory is a component called jsjr, with several Java classes and a JavaScript XPCOM object that implement remote method invocation between Java and JavaScript. The test directory contains some unit tests. This remote method invocation would be overkill for sending only one kind of message in one direction, but you might find the code helpful.