I have an application that I need to deploy that is a mix of pure PHP, JavaScript, jQuery, and AJAX. It runs flawlessly on all machines when called in a browser. Unfortunately, I also need to deploy this application to a machine that won't be able to run a browser.
Just running the file using PHP will output the resulting file, but does not execute any of the Javascript.
What are my options to get this task running? The machine will have access to xampp, but not to a browser.
Edit: the application grabs data from MSSQL, uses Javascript to turn that data into charts, uses an AJAX call to save those files to disk, and then calls another PHP script to mail a copy of the resulting files.
It depends on what your exact Javascript needs are, but unfortunately, if your application truly depends on a browser (and can't be ported to something more appropriate for the constraint), you will need to "fake" the browser somehow. Here are a few options.
PhantomJS is basically a headless Webkit engine (think Chrome or Safari).
HtmlUnit for a Java based solution, supported/developed by Mozilla
Other rabbit holes (Wikipedia/Headless Browser)
NodeJS offers a non-browser, headless, Javascript specific option, but will require your code to be more robust and generic than many code bases initially are when originally coded for browsers.
Related
I need to crawl a website, however, its content is dynamic. Are there any packages in Python that could call js functions? For example, suppose I have a link and JS functions 1, 2, and 3 in JS that I should call on that webpage, and I need the final webpage after all JS function calls.
Executing client-side javascript can get very complicated, so the most reliable way to run all javascript on a page just like a user would would be to use a real browser in headless mode.
Specifically for Python, there is a Python+Selenium combo for working with headless Chrome.
If you are willing to trade Python for Nodejs, a more powerful toolset is Puppeteer+headless Chrome (it lets you do a lot more than Selenium). There is also an early unofficial port of Puppeteer to Python but I haven't tried it and can't comment on how stable it is https://pypi.org/project/pyppeteer/
I need to run a Javascript file for a relatively long time(maybe about 5 weeks or so at one time), without it stopping or being interrupted. Currently the script is a client side script which connects to the server and receives data via Sockjs. There is no HTMl/GUI. There is only some computation.
I need to make sure the client always stays connected to the server all the time. I need to be able to run some script from the command line which is like forever.js. I have tried porting the javascript to node.js but it doesnt work. It only works in the browser. I have tried reading the file and doing an eval but none of it works. Are there any other options open for me? I have tried phantomJS but that doesnt work too. I have looked at How can I use a javascript library on the server side of a NodeJS app when it was designed to run on the client? and Load "Vanilla" Javascript Libraries into Node.js but I reapeatedly get SockJS is not defined. I guess the problem lies deep in the library and is not a simple fix.
Could anyone give me some pointers? What are my other options? Whats the best way to test a client javascript library which seems to work only on the browser?
This is the repo I am using :
https://github.com/sockjs/sockjs-client
It doesnt seems to be running on node. I tried to replace the script tag with require, and download the sock.js into a separate file and use it.
There are "headless" browser modules available. These produce a virtual browser environment that can be programatically controlled. The primary use of these is to do unit/integration testing of browser side code without actually running a browser:
Phantomjs
Slimerjs
These might fit your needs. You can create a nodejs script that will load the said code in a virtual browser page.
I'm working with an API with a feature that can only be accessed (easily) using Javascript, but I want to use the API to save a .txt file to my server. Is there any way to achieve this on a Mac OSX machine? I know that JS running in a browser is prohibited from doing this, so I guess this is really a two part question: (1) what's the simplest way to run a 10 line JS script on Mac OSX and (2) how would I write data to a txt file doing this?
You could go for a headless browser for example PhantomJS. I haven't used it, but it should run JS well.
The same restrictions apply though, no filesystem access from JS.
Unless you use something like the plugin framework in FF, in that case you have elevated rights for the scripts.
Besides that you could create a wrapper in php, perl or other language, and pass on the data from JS to them in an ajax call, and they write the txt for you.
Is it possible with Javascript or jQuery to convert mp3, wav, etc. to m4r format?
Let's assume you had a library that can change the format of files.
Let's also assume you only need the application to work on current browsers that implement FileAPI or FileReference so you can have access to uploaded files (you can't have access to them without FileAPI or FileReference unless you use Flash or Java Applets or equivalent technologies).
You wouldn't be able to write the output file back to the user because JavaScript is not allowed to access the local filesystem.
Your only solution would become sending the converted file to the server and the server sending it back to you with a force download directive so that the user will be prompted to download the results.
Now back to if there were a library that can the conversion (or even native JavaScript)... I haven't heard of any. It's not impossible to build one but it is impractical and wouldn't run very fast.
Edit:
Let's not forget Node.js!
It's a backend server that uses Google Chrome's V8 JavaScript interpretor/compiler. And it runs JavaScript as a backend scripting engine.
You have access to filesystem, databases and everything if you use that (or any other backend system for that matter) and still be using JavaScript. You can use libraries too. Either written in JavaScript or libraries written in other languages that have been linked to interface with Node.js.
Edit 2:
There is a PC emulator written entirely in JavaScript. It runs binary executables if you want it to. It's called JSLinux.
If you're feeling particularly rambunctious you can grab the ffmpeg binary executable (compiled with static linking). And embed it into your application code as an uuencoded string then use JSLinux to execute the commands and grab the results.
Indeed, it is possible doing this on the client using the latest js technologies. A web-worker thread can do the work in the background. At least in Firefox and Chrome it is also possible to read ("upload in memory") and write ("download from memory") files using the new W3C File API, see here.
I managed to read files via drag&drop from and within the client using google's GWT which in the end is plain javascript, so it must also be possible to do it "natively".
Besides that, the conversation algorithm of course has to be implemented in a javascript web worker to avoid blocking the gui. This should be the hardest part, but not impossible, though.
You would need a backend to do this. You may want to look into the PHPExtension of FFmpeg
I'm creating a client based application in HTML Application (HTA) and I would like to know if there's a object persistent library similar to python's shevle that meets the following criteria:
Should be able to read and write on file
Cross browser: should work at least on both HTA and on Firefox (through XULRunner) so that I'll be not tied to any vendor.
Written in JavaScript form
TiddyWiki is able to save itself, regardless of the browser used, though the codes that saves and retrieves files has to be refactored to meet my need.
Well, I wasn't aware that TiddyWiki has a github repository, and they organized the files by module.
I could just take the FileSystem.js file and build a nice api on top of it to simulate shelve functionality.