Load local files on Chrome-os - javascript

I am trying to create a JavaScript pacman game, but whenever I try and load my script files or images, I get the error:
The browser I'm using is chrome, and the files are stored in the same directory. I am running CHROME OS, so I can't just go into files and edit an existing flag.
Same for the images, except the file name is different.
Does anyone know why I am getting an error Access Denied, or how I could test the files?
The files are loaded using this format
<script src="Scripts/gamescript.js"></script>
<body>
<div class="game" id="game">
<img src="/Images/ghosts/red.png" />
</div>
</body>
Per request, here is my file tree
/Javascript_Pacman_Game/
index.html
/Styles/
stylesheet.css
/Scripts/
gamescript.js
myCustomLibrary.js
setInterval.js
/Images/
/Ghosts/
red.png
blue.png
pink.png
orange.png
scared.png
/GameElements/
board.jpg
bloop.png
superBloop.png
The problem isn't spelling or file permissions, and I can't run a local host because of Chrome-OS.

Try installing Web server for Chrome, telling it to serve files from your /Javascript_Pacman_Game folder, and testing your app at http://127.0.0.1:8887/

If you have to handle this from chromium OS (specially with dual boot cloud ready), follow the steps
Step 1:
Go to the shell prompt Ctrl + Alt + T on shell open the chrome_dev.conf
$ sudo vi /etc/chrome_dev.conf
The sudo default password would be 'chrome', The file may be write protected follow these steps incase if you stuck in step 1
$ sudo cp /etc/chrome_dev.conf /usr/local
$ sudo mount --bind /usr/local/chrome_dev.conf /etc/chrome_dev.conf
$ sudo vi /etc/chrome_dev.conf
Step 2:
Once you open up the file write --allow-file-access-from-files on top of the file
Step 3:
Restart the UI (if you are using windows dual boot press CTRL + ALT + F2) from dev shell
$ sudo restart ui
Once its restart the changes will get affect in chromium OS chrome, to check type chrome://gpu on your chrome browser
Under command line Argument you can find argument options.

You really should be running a local server. Apache, IIS, etc. Than you can run off localhost and have no issues.
BUT if you really want to run off the file system, you need to start up chrome to allow it.
You need to set --allow-file-access-from-files
http://www.chrome-allow-file-access-from-file.com/

It sounds like your permissions have been edited (or defaulted) to restrict your current user from accessing those files.
I managed to reproduce this error by creating the same file structure you have and then
right clicking red.png > properties > security > edit...
then denying access to this file from my current user. It seems that if you deny access via the directory you get a File not found error instead since the browser isn't even able to navigate to the directory in the first place.
Try checking your individual file permissions. If this is a default file permissions issue you may want to ask about how to fix that on a different forum.

The error is from your spelling, the first one you said
gamescript.js
and you called it as
script src="Scripts/gamscript.js"></script>
Check your spelling, you did not include "e"

Use Chrome Dev Editor as your IDE, then you can just hit the run button in the top left.
You could also use this Server.

javascript doesn't have access to the filesystem of a computer for security reasons do
<script src="Scripts/gamescript.js"></script>

Related

Error when trying to run JS in VScode for the first time (newbie)

So i just installed VScode on my Windows 10. I keep getting the following error:
"Can't find Node.js binary "node": path does not exist. Make sure Node.js is installed and in your PATH, or set the "runtimeExecutable" in your launch.json"
I've tried reinstalling VS and rebooting, tried installing from different folders (both on C drive and the second time i added it to my programs folder)
I tried installing a node.js extension which fails every time and then prompts me to try it manually...which then leads to a file downloading automatically, but when i add it to my VS folder through my file explorer, nothing happens still.
I tried installed a different node.js debugger
I tried changing my debugger to chrome too but all it does is take me to localhost:8080 and an empty page of course.
When i go through file explorer and look through the path of my .vscode folder, the nightly extension (node.js) is there....
I'm new to VScode and have just been using Scrimba's terminal to do my code but decided to try something more professional
I think you're putting node.js in the same folder/path as .vscode, this isn't correct. What you need to do is set node.js in your PATH which is different. See this answer for more information on how to set PATH/environment variables. Also install it from the official website nodejs.org. After changing your PATH remember to reboot.
I wouldn't recommend downloading "node.js extensions" as those likely are not legitimate, and as you've said yourself they don't work. Only download from the official website.
You have to install nodes from this website https://nodejs.org/

openJSCAD include files

I would like to load multiple files with OpenJSCAD.
I tried 1 without any success.
I'm using OpenJSCAD with Firefox on Ubuntu 18.04. I tried both the offline and online versions.
I have improved the section on include of the Userguide
You should be able to try it out with any of the three examples mentioned by putting the files of the examples in a folder and then drag and drop to OpenJSCAD
The result should be as in https://openjscad.org/#examples/platonics
Welcome in a world where complicated things are easy and easy things are complicated!
The include command of OpenJSCAD will search for include file relatively to the URL of the including file and there are limits to this when you try to drag&drop files via the browser and the behavior seems to be much browser dependent.
So it would be easier if your "workspace" with the file you'd like to use would reside within the webservice that the OpenJSCAD solution offers.
In the examples section of OpenJSCAD there seems to be one use of the "include" statement at this time see:
https://www.openjscad.org/examples/globe.jscad
You can try it out via
https://www.openjscad.org/index.html#examples/globe.jscad
Please note that how on refresh you get an error message:
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /openjscad.jscadplatonics/maths_geodesic.jscad was not found on this server.</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at www.openjscad.org Port 443</address>
</body></html>
To get the same effect locally you'd have to create a sister directory of "examples" in your local installation. This will not work if you call "index.html" with a file url
file:///usr/local/lib/node_modules/#jscad/openjscad/index.html#examples/globe.jscad
To show the principle of a "workspace" directory i have created a dockerized OpenJSCAD version which is available at:
It's also available via Docker Hub so you can simply try it out by running the command:
docker run --publish=8080:8080 --name openjscad bitplan/openjscad:latest
You should now have an OpenJSCAD running in a docker container on your computer which you can try out with e.g.
http://localhost:8080/
and specifically
http://localhost:8080/index.html#examples/globe.jscad
http://localhost:8080/index.html#examples/platonics
to see the include usage.
Now we need to apply this principle to the workspace directory which is prepared in the docker container and ready to be mounted locally.
To get this working some rules need to be followed which are currently discussed at:
https://openjscad.nodebb.com/topic/6/dockerized-openjscad
Mount your workspace directory
docker run \
--publish=8080:8080 \
--name openjscad \
--volume $HOME/openjscad/workspace:/openjscad/packages/web/examples/workspace \
bitplan/openjscad:latest
now the file from your workspace should be available via the corresponding url.
To try things out you might want to copy the platonics folder from
https://github.com/jscad/OpenJSCAD.org/tree/master/packages/examples/platonics
to your workspace folder and try the access with:
http://localhost:8080/index.html#examples/workspace/platonics
now you should be all set to use
include()
as requested

Unable to Run JavaScript in Atom with Script package

I am trying to run JavaScript code in Atom with Script package. It can run Python successfully, but with JS files it gives the following error message:
The system cannot find the file specified.
I had the same problem while analyzing some JavaScript code of an extension for Chrome.
Using: Windows 7 64Bit Atom:1.24.0 x64
Since I my coding Folder is somewhere else I copied the files in that folder. Let’s say:
C:\Users\USER\CodingStuff\
then it started working. I have also tried adding the extension file the Sources via:
1 - CTRL+SHIFT+I
2- Right click -> add folder to workspace
But that did not work.
Side note: node.js has to be installed on the system.
Hope it helps.
I know I am late, but if any other faces the same issue, my answer will be helpful.
Assumed that you want to run your javascript outside browser and you installed node.js.
There is a bug in "script" package of Atom. Check ur path of the script if there are spaces then this leads to the aforementioned error. Work around is remove spaces.
for ex:
E:\Java script\trial.js
change to:
E:\Javascript\trial.js

Node-webkit app talk to terminal

Is it possible for me to write html/css/javascript to have a button that'll open up the terminal program on my computer and run some scripts?
The scenario I want is:
On my ubuntu laptop, run my node-webkit app, click a button on the screen, a terminal opens, and start executing some scripts.
Thanks
from web page you cant do this but you can use node.js , if you want to make a GUI app with JavaScript you can use node-webkit with it you can build cross platform software that can work with Linux and execute commands in the terminal
You can do this from a webpage, but make sure your hosts.allow (or equivalent) is set to localhost only. Just run any web server with cgi capability and drop in your cgi script that runs your scripts into the cgi-bin directory. Then just add an empty form submit button or link to localhost:8080/cgi-bin/your_script
Slitaz uses this for their entire configuration system using busybox httpd and shell scripts, but uses shell generated interactive forms instead of a terminal. See: http://hg.slitaz.org/tazpanel/file/
Another way to do it without a web server (at least with firefox/seamonkey - not tried with chrom) is to associate a file extension so that files with that extension are opened with that script. Then just make a link to an empty file with that extension.
Use child_process module:
<script>
var cp = require('child_process');
function run() {
cp.exec('gnome-terminal -x bash -c "./your_script.sh; read -n1"');
}
</script>
<button onclick="run()">your_script.sh</button>
You can also remove read -n1 and simply run
cp.exec('gnome-terminal -x ./your_script.sh');
in case you don't want to wait for any key press.

How to debug node.js application with Visual Studio 2013 and Node Tools NTVS

I have moved an existing node.js + express project to VS because I prefer the IDE over JetBrains for now (used VS for years, only peeked into Webstorm).
I used NTVS new project->from existing sources and all files were imported successfully.
Afterwards, I opened the project settings of my project and set the node.exe arguments to bin\www, startup file for express.
When I press F5 (debug) I get the console.log messages I have put into the www and app.js files in the opening command prompt, and it looks like the server is running (cannot confirm, I want to debug if everything is working), but the VS debugger directly exits again, it also does not open any page in the browser I selected for debugging.
My node app actually is a REST webservice, so I want to test different URLs with different parameters.
Also, I cannot access the app on the port I specified, though when I directly start it from node.exe I can, even though the command prompt is still open.
(I have NTVS and WebEssentials installed - some operations take a long long time, but I attribute this to NTVS being still an early version.)
Question: how does the Visual Studio debugger stay connected to the node.js application so I can use breakpoints and use any browser then to connect and test different URLs? (Even a breakpoint put on the console.log that gets printed during startup is not being triggered.)
For everyone who asks receives, and the one who searches finds....
(and yes, I did spend a long time searching and trying before posting here..)
Kind of nice to debug node.js server with VS..
hope this helps someone
Edit: The arguments to node.exe can be hard to read in the image. It must be
--debug=<portno>
that is with two dashes (and not just one) to specify the debug port.
Not so much knowledge on expressjs but with a recent release of NTVS 1.0 Alpha, I did find it supports remote debugging which can be also used to debug nodejs app running locally - anyway haven't tried if it works with nodejs app + expressjs but it should.
I followed the step in this video https://youtu.be/-ir9ZB8lUg4 which is
Run your nodejs with node.exe RemoteDebug.js <your_javascript_file>.
RemoteDebug.js has come when you install NTVS.
In Visual Studio, select Debug > Attach to Process
Select Node.js remote debugging for Transport
Enter localhost:5859 for Qualifier
Click Attach
This will put Visual Studio in debugging mode which you can set a breakpoint, do step-in/step-out, very same experience when you use VS to debug .NET app.
Its pretty straight forward with NTVS, you can download required version for your windows from github here
Once you install NTVS, NodeJS project templates will be added
Now, Goto File->New project -> Basic NodeJS Express 3 application (it will be available in javascript project templates)
Now just goto debug and select Start Debugging, add breakpoints where ever required and you can start debugging

Categories

Resources