Manipulate sqlite databases without html5 browsers - javascript

I'm trying to create a client side app in javascript that downloads a sqlite database off a server and allows the user to modify it. This app needs to be all client side though, and can't rely on features only present in firefox for example. Is there any framework you are aware of that provides these features?
(Perhaps emulated of sorts?)

Short answer: you can't.
Long answer: Javascript, by design, cannot access local machine files. If it's okay to keep the db server-side and have the client interact with it, the server can execute queries and updates to the DB based on what the client asks it to do (a la web service). This is true for HTML5 browsers as well.
Some browsers, such as firefox and chrome, come with packages that will allow the browser to talk to sqlite dbs, but they are not written in javascript and can do things that javascript cannot, which is why they are included as browser-specific packages instead of as js scripts.

Related

Javascript access desktop application

I'd like you to give a tip for my issue. I'm pretty new to javascript so I don't have such overview.
I have a desktop application - it's basically a storega for data (+ some GUI). And there's a set of Javascript files, which are ment to get data from desktop application.
These javascript files runs in every browser - for each browser I've made a extension wrapper. There is also a testing java-webkit browser, which injects these files directly (so no extension's API).
So I need to create communication API between Javascript and desktop application, which is able to run in every environment (browser-specific implementation would be too "expensive" to maintain).
So I was thinking of sockets. But there is only Websocket protocol support in javascript. Client looks simple, but I'm afraid that server-side would require too much work and dependecies.
Could you give me a tip, for other technologies, which compatible with my requirments?
And second question - to the sockets - would it be even possible to access socket on "localhost:port" from these's javascript files, when they are Content scripts running in page's context?
Thank you for advice.
Sockets is the way to do it. #Luckyrat has provided some code on how to do it from a Firefox Addon:
https://stackoverflow.com/a/17459064/3791822

Saving data to a local file using only JavaScript

The set-up in question:
I have a stand alone, offline, kiosk mode instance of Chrome running on a Windows machine. I have full access to the system and any admin rights. I can start Chrome with any flags set or unset.
The task:
I have been asked to create a log file which tracks user activity within the offline app I am coding. It's a simple form of analytics which will append each event to the end of the file separated with a comma. The file will then be sent to a server once a day via a scheduled task. (None of this is my idea so please don't troll me)
Ruled out:
Any server side code - I have lobbied for Node, PHP etc but as this will be distributed to many different installations so we cannot guarantee this will be installed.
Flash/ActiveX/Java - ideally would like to avoid this (even though these will be installed by default)
Possible solutions:
File API - I have looked at this but AFAIK if opens dialogue boxes to save the data to each file and this needs to happen in the background.
Security - I have read in other SO Questions that this can be achieved if the security settings are reduced but no-one goes on to explain which ones. Is there a simple flag which allows it?
How to enable local file system read write access from Google chrome? - similar question!
Ideal result: (something akin to PHP)
$file = 'log.txt';
$current = file_get_contents($file);
$current .= ",clicked:link";
file_put_contents($file, $current);
Possible ideal side result: proving this isn't possible and forcing PHP/Node/Java to be used ;)
In reply to those suggesting local storage : I'm not storing unique key/value pairs and that is very much like setting a cookie. Similarily there are file size limits.
To those suggesting web SQL such as SQLite in chrome - there are file size limits if it's not a chrome extension. The only way I see that working is if I were to find the location of the file in the windows directory (C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default\databases) and upload that from the schedules task. Perfectly feasible but it is not a desirable answer.
You could use HTML5?
http://diveintohtml5.info/storage.html
var foo = localStorage.getItem("bar");
// ...
localStorage.setItem("bar", foo);
You can use the Chrome Apps File API, you will need to grant access to the file via a user action once, but after that you can get access the file again by using restoreEntry
You can use localStorage to save offline data. It's impossible to access other files using Javascript since it's a violation of the sandbox.
From http://en.wikipedia.org/wiki/JavaScript#Security:
JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using two restrictions. First, scripts run in a sandbox in which they can only perform web-related actions, not general-purpose programming tasks like creating files.
You may want to look into Local Storage which is part of the HTML5 spec.
This will only be supported in modern browsers though.
If you need to use older browsers then may still be able to achieve what you're after using dojox.storage
Use HTML5 features like Web Storage or Web SQL database to store your logs.
Whenever needed read logs from the client side storage and send it back to the server & delete the client storage.
Refer http://www.html5rocks.com/en/features/storage.

JavaScript/JQuery communicate with SerialPort/COM1

is it possible to force any communication from e.g. Javascript/JQuery to any serial comport?!
google is not able to answer that question.. but anyway it should be possible.. env is firefox in my case..
ideas/knowledge is very welcome.
kindly tape
I think it is possible..
Look to: jUART, Cross platform browser plugin for serial port communication from JavaScript
https://github.com/billhsu/jUART
with chrome it's possible ,
here is the link for documentations :
https://developer.chrome.com/apps/app_serial
or
http://www.fabiobiondi.com/blog/2014/02/html5-chrome-packaged-apps-and-arduino-bidirectional-communication-via-serial/
Yes you can, but not with a typical browser. Browsers are sandboxed to not have access to the local file system (except cookies) so that malicious sites can't read from / write to your hard drive. As far as I know there is no way to override this behvior (short of writing your own browser).
However, this can be done in JavaScript using Node.js. It runs as a process rather than in a browser window and can access the file system. Specifically, there is already an npm module (node library) for serial communication: https://github.com/voodootikigod/node-serialport
Alternatively, you could always just spin up a local web server (via node.js, php, rails, etc). Web servers can access file systems, and therefore should be able to access serial ports.
Hope this helps.
Update to this thread, if you are using chrome you may use Web Serial to communicate using web to serial port.
https://chromestatus.com/feature/6577673212002304
https://web.dev/serial/
kimstik's suggestion, using the jUART plugin for the browser is an excellent solution.
Another possibility is to use a middleware, that facilitates the serial communication and provides a web interface, that JavaScript can interface with using AJAX requests.
Python could be used, e.g. a script using a combination of pySerial and python-bobo.

HTML/Javascript/CSS Desktop Applications

I have written a program in HTML, Javascript and CSS, and I am displaying it in IE. I'm dependent on IE because data is written to, and read from an Excel File and I need to use ADO for that.
However, the "An activex object is trying to interact with oter parts of the page..." prompt is very irritating, seeing as it is an application that will be store locally on the user's computer, and will not be a web application. I find HTA difficult to debug and it seems as though it hasnt been updated in a while. I can't add my application to trusted sites and use custom level to deal with the activex prompt because it is stored on my computer. I was thinking on storing it on my local host, as I would then be able to add it to trusted site, but this would require adjustments to the user's computer.
Ao my question is, what is the best way for me to display my html/javascript/css program, as a desktop application, with little or no need to change any settings on the user's computer, that could read/write to and from excel spreadsheets (or if you know a better way of dealing with this data), and is stores on the user's couter rather than as a web application?
Any advice would be greatly appreciated:)
Write a windows application instead and use the Apis of excel. Your model of HTML CSS js will not work well with security.

web page to read client side registry

I currently have a web app that uses ActiveX / JScript to read files and to read the registry for a web page. Originally when designing the page, it was supposed to be on a site that only supported IE...then things changed and it is no longer that way. My question:
HTML5 is able to read files. Is there any way to read registry entries outside of ActiveX and internet explorer using javascript/html? I'm trying to avoid having to port the entire applet over to use Java, but that may be my best method.
The page makes no modifications, it only reads text files and registry entries.
It is not possible without a third party plugin.

Categories

Resources