Cannot open a local file from webpage - javascript

I want to open files from webpage. For example when we try to download a torrent file it redirects us to utorrent app and it continues it work. I also want to open a local file somehow using OS software. Like a video file using pot player. Is there any possible solution for me ,like making a autorun in pc to run that . Anything it may be please help me.😔😔
I searched and found a solution to open a software using protocol, but in this way I cannot open a file in that software.

Opening a specific file in a specific software would usually depend on passing some URL parameters to the protocol-URL of the app (e.g., opening a file in VSCode would use a URL like vscode:///Users/me/file.html, but this functionality would have to be explicitly handled by the app itself though, so the solution for each app would be different).
Otherwise, if the app doesn't support opening a specific file itself through a URL, you'd have to use some scripting software (e.g. AppleScript if you're on macOS) to dynamically click/open certain programs on a user's computer.

the link acts as a magnet so your torrent application is opened maybe delete torrent for sometime till you finish the project, i know how to open image in local files in html but it will only be visible to you, you can do audio and video files also using <source src="movie.mp4 and on next line `type="video/mp4">

Related

Protect contents of Electron app from being stolen

I'm planning to create an Electron app. The app has content of multiple mp3/png/svg files which are going to be rendered inside the app. I don't want anyone to open an audio or an image outside of the app. I researched a lot to find a solution to protect theses file so that if someone installed the app won't be able to open and use the files outside of my app but it seems that it's not possible...
Note: simple protection solution with minimal security is accepted too...
Note 2: Can we store the files (mp3/ png/svg) without any extension (this way users can not open them directly on their machine) and then open the files via electron app (we have the name and extension stored in our app so we have the extension to attach to preloaded file and open the file) I mean can we preload the audio file without extension and then open the preloaded audio with mp3 format as a work around?
I saw a clever "solution" for protecting multimedia assets back in the days of interactive CD-ROMS.
The trick was to write some junk text to the end of the .mp3 or video file in order to corrupt the file and make it unplayable. Then in the app, to play the file, the file would be written to a temporary directory with the junk text removed so it could be played.
Not foolproof by any means but it prevents casual copying assets out of the app bundle.

Can a Chrome Extension Dynamically Add JS Files to Local Extension Directory? User Upload or Saved From the Web?

I'm wondering if it's possible to for certain JS files to be added to the web extension directory later?
Like say I have an app where users can select certain settings from within the app and those files (js and html files, images or blobs) are somehow added into the extension from the web. Like some sort of ondemand updater without using any native apps but it seems that upgrades are done by the appstores automatically.
I'm reading the files using ajax and adding them to indexeddb but because it could be more than one file that's getting messy.
Say a user wants a certain feature on the extension and there's an html page, js files and images then this gets downloaded to a certain folder inside the installed extension.
function download() { //only saves to downloads directory
var imgurl = "https://www.google.com.hk/images/srpr/logo11w.png";
console.log('download');
browser.downloads.download({url:imgurl},function(downloadId){
console.log("download begin, the downId is:" + downloadId);
});
}
I also tried the chrome download function above but that only works for the downloads folder not the extension folder.
Is there any way to make a custom updater?! I know we can't save to disk but any leniency or workarounds for the extension folder?! Even something silly like making a shell call to some dos (and linux/mac) thing that saves the file to the extension folder. I can fetch the files, just not save them.
Ok so I'll put it as an answer. This is the solution I'm leaning on which works for my scenario and I've listed some alternatives below:
Having the other files as separate extensions and giving the user an install link instead where they can install that extension, then those child extensions talk to the mother extension and they know the address to the resources in their child extension folder, so the mother gets the just the file locations from the children to load those assets from that folder. The child extensions are like bundles of those html and js with a background script which sends the addresses of these items to the mother.
https://developer.chrome.com/extensions/messaging#external
The drawback is that I'll have to see how that affects the urls like if I inject the html page from the child extension folder into the main interface using ajax then I can't use relative url's to any images in that 'cos the urls are relative to the mother extension folder.. I'll have to rewrite the child extension urls with the absolute paths into the html page to load images and js from the child extension html code which has relative urls.
Pros:
Cleaner and more persistent than indexeddb.
Files can be loaded normally from disk.
Cons:
User has to install separate extensions.
URL structure might be a bit confusing, need to rewrite urls if loading html from child. However this is only for image src's and where the javascript is loaded from so it's not such a big deal.
Other Possible Solutions:
Indexeddb which I'm already doing seems to be the preferred way of doing this but I really do not want to store every html asset in indexeddb. The upside is that while extensions need to be installed, this method can be done silently fetching and adding files without user interaction and indexeddb seems to be somewhat persistent. Might still end up using this because it is silent but having to load each asset from a database sounds like a nightmare.
The File Handle Api might have worked if I was working on Firefox only https://wiki.mozilla.org/WebAPI/FileHandleAPI
I haven't tried the shell copy, maybe if I fetch with ajax and then save to disk using some dos function and then doing different save functions for different OS systems.
Filesystem Api only saves to downloads and doesn't work for extensions anyways, so that's useless.
UPDATE
In windows there isn't any sudo, but this worked without admin priveleges for a subfolder (not on the C:\ root though). It would work for a linux only app very nicely. If I just wanted to save a file to a windows machine this might work.
Shell copy method would be to grab the contents of file with ajax from the local or remote location, output to DOS as a stream to save to file on windows. And do this for every operating system with a shell exec command or detect the OS and do that command. This way I can even put the files in the exact folder location.
Like say I make this sort of command from the contents:
//To append you can use >> instead of >
//folder seems necessary, can't save to root without admin
echo the content I want to save > C:\folder\textfile.txt
I thought of calling it using shell exec that only works in nodejs, so digging through the other answers on
How to execute shell command in Javascript
//full code to save file using javascript on windows
var shell = WScript.CreateObject("WScript.Shell");
shell.Run("echo content to save > C:\folder\textfile.txt");
The shell command doesn't seem to work. i can't find what this is for. There doesn't seem to be a shell command in regular javascript for windows. It seems to require IE ActiveX. Doesn't work with Firefox or Chrome.
Extensions can't modify their sources because the browser verifies them and resets/disables the extension if they change. Also, in Firefox the extensions aren't even unpacked.
The solution is actually quite trivial: save the code in any storage (localStorage, chrome.storage.local, IndexedDB) as a string and then add it in your extension page as a standard DOM script element. You'll have to relax the standard CSP a bit for that.

Open file in VLC from a href="path/of/file..WAV"

I'm looking a way to open a .wav49 on VLC with a link from my web app. Since files with .wav49 are not supported by <audio> tags. And I can't change the file type to a normal .wav or .mp3 due to several reasons.
The audio files are located in a shared folder on my server (which is a Windows Server 2016), so everyone on our network can access them.
The goal of my app is to make the audio file searching something easy.
I've been looking for options like change the format in backend and stream a .mp3 file to the audio tag or a plugin that allows to play .wav49 files but it seems that the easiest way is just to send the file to be opened on VLC.
The only I have for now is this
<a href="file:\\CENTRAL\path\audio.WAV">
I also tried with
<a href="file:\\CENTRAL\path\audio.WAV" download="test">
But neither works.
Only in Firefox, when I click the link ask me if I want to save it or just open it, but both of the options download the file. I don't want to download the file, I just want to launch an alert asking if the user wants to launch VLC and open the audio.
There are some examples of what I want to do, like roblox.com when a user click on the play button and he has the app installed, the browser launch the app on the local machine and gives the params of the game the user wants.
Another example is comodo remote control, when an user of comodo is in the web device manager and wants to begin a remote session, the user just click a button and an alert appears asking if the user wants to launch the remote control by Itarian app, if the user says yes, the app is launched in the local machine.
I found this Open video stream on VLC Player through the browser but it seems doesn't work anymore.
First of all, the standard path separator to be used here is a forward-slash, also if you want to link to a local file you need to use the file:/// prefix with three slashes. For network shares you would use two slashes: file://smbhost/path
So i would recommend you try the following:
<a href="file://CENTRAL/path/audio.WAV">
Hope this helps

How do I open a program that is installed on the desktop from a web page?

someone knows how to open a program that is installed on the desktop from a web page, something like the onedrive option where from the web you can tell them to open a document and open word with that document or like when you open a torrent link ?
You basically have to download a file that is recognized by the program you wish to start. That program has to be pre-installed on the machine. The file should include instructions the program understand, and can execute.
In any case, this is quite fragile, and depends on many variables you have little control over, including the user, who might decline the download, or just save the file without opening it. So you should try a different approach to achieve what you want, than running a program on a user's computer.

Javascript local file saving or onSave event to get saved filename

I'm developing a web app that needs some sort of filesystem access. Ideally I'd want to be able to "Open..." a file into the app and then "Save" the file back to local filesystem at the location that the user opened it from.
Currently, we use a java applet to achieve this functionality, but since java is going out of style, we're needing to do this with javascript and html5.
Obviously, this can't be done because of security reasons built into browsers, so I'm trying to somewhat emulate it.
I'm using the html5 file api to successfully import/open the files, so that's half the battle. The hard part is getting the saving feature. I'm getting close using an iframe and content-disposition, but problems arise when browsers are set to automatically download the files to a downloads folder... users may get confused and be unable to locate the file they just downloaded.
So, my question is this: is there some sort of onSave event or some kind of way for the browser's "Save As..." window to return at least the filename that the user saved the file under?
Also, I've looked into the filesystem/fileWriter html5 apis, but from my understanding they're limited to only a sandboxed area of the local filesystem and only available in chrome dev releases.
Any help would be appreciated!
No, there is no way to do that with pure JavaScript. You can manage to trigger a download with data URIs or an iframe with some headers but you can't circumvent the browsers' download managers.
You can either use a Flash or Java applet to handle the saving for you, or ask the user to right click on the link and do save as, then he might be able to choose the destination.
One popular option using Flash is Downloadify.

Categories