Executing bat file via Chrome - javascript

How to run a local bat file on a js button click using Chrome browser ?
'window.open('file:///C:/Test/Test.bat' - Opens the bat file contents in a new tab instead of executing the file. It works fine in IE browser. Please suggest how to achieve this in chrome without using any plugins.

You can't do that.
Otherwise it would be a security problems because hackers could use it to do malicious things on our computer.

Related

vshaxe - how debug Javascript target in browser

I'm pretty new in VS Code, and I'm looking for an automated solution to debug Haxe JavaScript project.
A way to open or live-reload browser after compilation, like in FlashDevelop, Intelij.
Now, I use an external localhost server (MAMP), and after each build I reload the browser manually. It works, but is not very efficient.
Lets me know how you do that. ;)
For info, I'm on mac
Check out the MIX Live Server extension. You can give it a path to your index.html, for instance if it's build/index.html:
{
"mix.rootPath": "build"
}
and then it will detect file changes and reload the page automatically. Note that this does not open the page in a browser, but a separate VSCode tab.

Chrome on android - not loading local website javascript and css

I have strange problem on Chrome for Android with local website.
It works perfect on Firefox for Andorid, but not for Chrome.
On my site here: https://passcombo.com there is download link with a zip file.
What I do is:
download file to local file system (not SSD! - external storage makes
another problem!)
I unzip the package and go to the site in local storage using File Commander
I open the html file with Chrome - only HTML loads, no CSS, no JS, no images, no fonts.
Looks like there is path problem with relative paths?
But firefox works!
Working alternative is Firefox, but there you need to write correct strange path: "file:///storage/emulated/0/..../...html"
But...
Currently Chrome is mostly used on Andorid so it's bad local sites not working :/
It doesn't work opening with file explorer, you have to write the path in the address bar file:///sdcard/Download... or wherever.
JS works with Chrome on local html file in my Galaxy S6.
The only solution I found is to:
[update 2021] use Opera (Firefox did work before recent update!)
copy folder with my html/css/js to local storage
(somewhere)
open the sitewith path like:
[current Opera] file:///storage/0000-0000/MyFolder/index.html
[old in firefox ] file:///storage/emulated/0/myfolder/index.html
where 'file:///storage/0000-0000/' OR 'file:///storage/emulated/0/' is the main path to local storage, and if you copied your folder somehwre deeper then you need to change the 'myfolder' to /somefolder1/somesubfolder/.../ sth
Shame it's the only way to create a web browser app for adroid.
It is possible using a HTTP server app on your phone.
For example the SimpleHttpServer.
Set the "Document Root" in the settings of that app to the folder in which your html files reside. Start the server and you will see a local link.
Click on that link and choose the html file you want to show.
If you declared your assets relatively those assets will loaded, too.
Seems like the only directory Chrome reads local files from is file:///sdcard/Android/data/com.android.chrome/files/Download/
The only solution worked for me in Android is the HTTP Web Server (I used Simple HTTP Server).
Installing different browsers didn't help:
(Apr-2021) I tried installing various Browsers (Chrome, FireFox, even Opera etc.) in Android but none worked. In all cases, when I navigated to the folder containing HTML/JS files using local file:/// URLs ('file:///sdcard/' or 'file:///storage/emulated/0/') browsers only displayed the folders but no files.
When I used the absolute path to the HTML file the browsers used content:/// protocol to
render static HTML content, i.e. it did NOT allow execution of JavaScript code.
In my Android OS version 7, to open a local html file with css and javascript in Google Chrome browser (ver. 64.0.3282.123) I have to open it through an address bar typing as file://localhost/sdcard/, then navigating to the file location. In spite of mention sdcard in the address, it opens an internal storage (and my device has actual removable sdcard as well).
Currently, I am also facing this problem. Chrome does not link to other files on the device, but you can use js and CSS by, using <script> and <style> tags and these will be included in the web page. But, for other files, like image, audio, videos, etc. it can't be done on Android still without any server established by 3rd party apps.
Install a text editor from playstore . Its name Acode
Got to your local file storage , then choose your .html file and press long time.
After press long time on .html file , you will see more (left side of your phone screen)
From more menu, chose open with option
Choose Acode text editor
When html file open on Acode editor, then preview it from Acode text editor.
that's all. It will works 100%.. (sorry for my english)

Do cookies work when the webpage is stored on a computer?

I have been trying to get my head around how to use cookies on a webpage, and on a webpage designed to test cookies I have been consistently been unable to read a cookie, despite apparently being able to make and delete them.
I would like to know if cookies only work on webpages stored on servers, as I have been using the functions from http://www.quirksmode.org/js/cookies.html , which seems to be recommended by many people so I doubt the code is at fault.
Can anyone help me with this query?
Thanks in advance,
Vulcan
By default, no they do not. But you can have Chrome browsers support "File" cookie by passing the option:
--enable-file-cookies
...into the startup command. (i.e. the windows shortcut that starts your chrome browser).
In windows, I also setup a shellext to do this for me, so that I only need to right-click on the file in File Explorer to launch chrome with the option.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\Shell\Open with GoogleChrome64]
[HKEY_CLASSES_ROOT\*\Shell\Open with GoogleChrome64\command]
#="{path to 64bit chrome.exe} --enable-file-cookies \"%1\""
[HKEY_CLASSES_ROOT\*\Shell\Open with GoogleChrome32]
[HKEY_CLASSES_ROOT\*\Shell\Open with GoogleChrome32\command]
#="{path to 32bit chrome.exe} --enable-file-cookies \"%1\""
If you want to use this approach, copy and paste the text above into a plain-text editor (notepad), replace the location to your 32bit and 64bit chrome.exe location. Save the file as openwithchrome.reg then double click that file via File Manager. That will add the necessary bit to your registry that will allow you to right click on a file and choose which browser you want to open the file with.
If instead you want to edit your startup icon, right click the icon and choose "Properties". In the "Target:" box, after the .exe (which is already on the target line) add the option in quotes:
{path}chrome.exe "--enable-file-cookies"
...click Apply then OK. When you start via that shortcut it should work for you.

Download multiple images without asking in Chrome extension

I am currently creating a Chrome extension (which uses javascripts mainly) that allows users to scrape the images on a webpage and download them. I have finished the link scraping part, and the code will return an array like:
["http://example.com/image1.jpg","http://example.com/image2.jpg"]
But how do I download all of the links in ONE CLICK? I tried listing all photos on a new tab and let the users to Ctrl+S save the page. But this greatly affects the UI and I do not like it. I do not host webpage so server side script may not be working.. Any other solutions?
As far as I know, Chrome extensions technically can't save files to disk like Firefox.
The only way to do this is using NPAPI
Unfortunately, extensions using npapi will most likely not be accepted by the Web Store due to security problems. Of course it'll be okay if you use it for yourself or host the extension on your website.
You can install and examize the code of the following extensions, maybe you can even use the provided npapi too:
Screen Capture (by Google) https://chrome.google.com/webstore/detail/cpngackimfmofbokmjmljamhdncknpmg
Chrome Toolbox (by Google) https://chrome.google.com/webstore/detail/fjccknnhdnkbanjilpjddjhmkghmachn
Awesome Screenshot: Capture & Annotate https://chrome.google.com/webstore/detail/alelhddbbhepgpmgidjdcjakblofbmce
Download Asisstant (by Google) - got killed I guess.

How do you log to the error console from untrusted Javascript?

In Chromium, 'console.log()' lets you print to the error console, but only from javascript embedded in the html, or in a .js file on the local machine.
What are your workarounds for debugging Javascript that is contained in .js files on a remote machine and included in a page?
Add breakpoints and / or watch expressions.
See http://code.google.com/chrome/devtools/docs/scripts-breakpoints.html
I recently had to do this with a Facebook SDK javascript, hosted by Facebook. I downloaded the script and hosted it locally for debugging. I could then add in all the console.log messages I wanted.
When everything was done I removed the local file and returned to Facebook's hosted script.
Phil's suggestion of breakpoints is also very useful when you want the value of a variable at a specific location in the code.
Another useful technique for code executed upon a user action, such as a button click, is to use the Scripts tab of the Chrome inspector, or FireBug in FF, to edit the javascript prior to execution. I've had limited use for this, but it's quite useful from time to time.
The problem is cross-domain security policy. Only javascript from the domain of the html file can use console.log

Categories