How to run JavaScript from local files in Google Chrome? - javascript

I have encountered this problem of JavaScript not running from local files when testing a website.
I am in great despair and need your help.
I have linked the JS correctly and everything, but it's just not working.
All settings are correctly enabled in Chrome.
Thanks!

Any problem caused by web browsers treating local files different to network files is best solved by installing a web server (there are many free options) on your development machine (optionally inside a VM) and testing through that.
This deals with many different issues include ones related to cross-origin security and relative URIs.

Related

XHR local files from a local file

I have a local (file:///) HTML page that tries to AJAX resources from its local directory. For years now Chrome has blanket forbidden all XHRs to file:/// URIs regardless of origin, which is annoying, but at least there's Firefox. But recent Fx versions have started replicating this behaviour. This seems like a good time to solve the problem once and for all. So:
How do I mark an entire local directory (and preferably its subdirectories) as being a single origin for the purposes of XHR and CORS?
It would be nice if:
It Just Worked on recent desktop Chrome and Firefox versions
The constituent files were separate files for easy editing and not bundled up in some archive format
This sounds like just the kind of problem that MHTML or MAFF or webarchive would help with, except that they're not universally available, or are deprecated, or both. Plus having the constituent files easily editable is important for my particular use case.
"Solutions" I'd rather avoid:
Command line flags or browser options (I don't want to have to use Chrome's --allow-file-access-from-file or Fx's suggested privacy.file_unique_origin pref)
Running a local web server just to serve up static files on a single machine
Embedding my data in javascript code or massive data: URIs
Making an Electr*n app
What's best practice here?
How do I mark an entire local directory (and preferably its subdirectories) as being a single origin for the purposes of XHR and CORS?
You can't. You'll have to use one of the solutions you'd rather avoid.

How do I make a chrome extension that will take the current webpage and upload it to my custom domain via FTP so I can view it on a phone?

Overview
I am trying to make a Chrome Extension that takes the currently open html page and all its dependencies (CSS, JS) and uploads it to a custom domain via FTP. I would then be able to open it on my phone to make sure the website looks good on a phone.
Basically, I am trying to replicate the VSCode extension Live Server's functionality, but with it uploading the file to a custom domain. I know you'd normally be able to access live server's locally hosted server from a phone, but my university's internet setup doesn't seem to allow for this, hence my desire for an extension like this.
All I know about my hosting service is that it uses cPanel and supports FTP, which I assume is all I need. I can set up new FTP connections and logins. All the FTP details in the code will be hardcoded, but drawn from a separate file and .gitignored so they aren't in my commit history, which I hope is enough.
What I've Tried & What I'm Stuck On
I have most of the chrome extension stuff figured out; The FTP transfer process is what's giving me issues.
I first tried using chrome-app-ftp, but quickly realized that was old and was running into issues, so I switched to jsftp.
I used browserify to fix the "require" issue, and that cleared up some stuff.
I'm currently stuck on the following bug:
Error: TypeError: createConnection is not a function
I've done my research, and I do not think the error is because of an issue in my code; I believe that it is just a limitation of the tools I am using. This seems to be an issue with front-end JS not supporting the "net" module, which brings me to my question.
My Question
How do I circumvent my lack of support for the "net" module in the front-end? Do I need to set up some sort of local back-end for this with node or something like that? I have basically zero experience with anything back-end, so I might need pointed towards what sort of back-end is best for this. I more just need to know which tech stack is best for doing this.
If additional information is necessary I'll be checking back frequently and happy to help. Thanks in advance.

Simulate XMLHttpRequest as from localhost or Remote Connection to a machine

I have a website hosted in ISS (can be other) that loads when it's called on localhost but not from extern :) like: http://:8081/Website.html.
The verification whether the website is called from localhost it's on the client in a js script that I can’t modify as it’s encrypted.
So I was thinking at two options:
Develop an ASP application that has a remote desktop connection to the machine that host the website (not some many example on how to).
Maybe configure the IIS configuration (didn't found how)
I'm out of ideas
Do you have any other solution or can you point on how can I do one of the above?
I have tried the WinForm solution from here: https://www.codeproject.com/kb/cs/remotedesktop_csharpnet.aspx and it doesn't work. And I prefer a website.
Updates:
The only working solution that I have for now is to configure a Remote Desktop Services (Web Access) as I hosted the application on Server 2008 R2. Then I only shared the browser that has the localhost page as default page
The javascript files are all minified and encrypted, meaning that if I search localhost as a word in all the files, nothing shows up. So fixing the client will be hard.
Is it possible to create a new Site Binding on IIS and access the site using the binding hostname? This requires your network DNS to register the hostname to the IP Address.
I assume you are dealing with encrypted(???) javascript that is hardcoded to display DOM only if it is loaded from localhost.
If by encrypted you mean minified you should still be able to find reference to "localhost" and modify javascript in minified version. If it is really encrypted by a wrapper of third party javascript library then I would suggest you to rewrite javascript. I mean how can there be any quality code in javascript code that is hardcoded to load only from localhost?
Fix the client and stop exploring other solutions like remote desktop connection. None of them are practical and sustainable solutions.
I think you need to use WebRTC, but it's supported for Chrome and Firefox. It allows two users to communicate directly, browser to browser using the RTCPeerConnection API.

How to fix Google Analytics "analytics.js" net::ERR_FILE_NOT_FOUND?

The relevant line of the Google script is:
(window,document,'script','//www.google-analytics.com/analytics.js','ga');
I am running this particular file locally (as in, I double-click "index.html" on Windows Explorer and it opens in Chrome.
After about a minute of trying to load this file it fails with net::ERR_FILE_NOT_FOUND reported in the Developer Console.
I understand why this is happening, it is trying to load this as a local file. If I do this it works just fine:
(window,document,'script','www.google-analytics.com/analytics.js','ga');
In other words, I eliminated the //. This would work just as well:
(window,document,'script','http://www.google-analytics.com/analytics.js','ga');
Is going explicitly doing it this way to only track real websites?
If so, how are you dealing with this issue for local development?
I do run a VM with Ubuntu server for local development of more elaborate sites. In this case I was working on a single file landing page that I knocked out quickly and wanted to just test just as easily but ran into the browser hanging waiting for analytics.js
Is it safe to remove the // or add http: in general terms. I don't generally like to modify Google code unless I fully understand why they are doing things in a specific way and what the consequences of my actions might be.
Instead of viewing the file locally, run it through a local webserver. Two easy options are
XAMPP: http://portableapps.com/apps/development/xampp
Uniform Server: http://www.uniformserver.com/
Both require no installation. If you have Visual Studio or WebMatrix, you can also run it through Cassini or IISExpress.
It can be that you are using a VPN(Virtual private network) which analytics blocks. Try loading https://www.google-analytics.com/analytics.js
If id does not work try disabling the VPN and try again.
Or as someone else mentioned it could be that your AdBlock is blocking it.

Pure Javascript FlashPlayer: why can't I make it work?

There are some demos here:
http://paulirish.com/work/gordon/demos/
I downloaded blue.html as well as blue.swf on my local pc. But opening it I can't make it work.
Why ?
If you're using it on your local PC using file:// URL's, I'll bet a beer it's not working due to browser security restrictions. You should be getting warnings in Firefox's error console if that's the case.
You'd then need to test it on a web server, or set up a local web server accessible through http://localhost.
It may be that you are trying to play an incompatible .swf file. According to its gitHub page, the player can not render any .swfs over version 2.
A SWF Tag support table is on Github here,
http://wiki.github.com/tobeytailor/gordon/swf-tag-support-table/

Categories

Resources