Not allowed to load local resource problem? - javascript

i'm trying t use Backpack React Scripts but it won't run the local resource,
i tried to change the DNS server and use web server for chrome but it did't work
any help please?
i'm trying t use Backpack React Scripts but it won't run the local resource,
i tried to change the DNS server and use web server for chrome but it did't work
any help please?

Related

How to run a Dynamic website with a http server

I am trying to run a dynamic webpage on my pc using a html server.
I have a website that needs to access jquery through a CDN however I cant do this normally as Chrome doesn't let me because of CORS policy.
I did some research and found that I could use python to start a http server with python http.server.However, this only works for static webpages.
How do make a dynamic http webserver.
Any help would be appreciated.
Thank you very much.
I have tried using python http.server however this only works for static pages and i need something that works for dynamic pages.
I just found out you can download an extension in visual studio code that does this.
Thank you so much for the suggestions.

Trying to make a chrome extension with socket.io

I am trying to make my chrome extension using socket.io, but I am facing a lot of difficulties importing the socket.io client into my application.
I am using Manifest V3 which means I only have one service_worker, so I tried using importScripts but that does not work for some reason. I cannot call the io() function after using importScripts. Then I tried changing the Content Security Policy to get it from the CDN but I get an error saying that it's invalid.
Any idea on how I can do this?
About the importScripts, you can try to bundle the background script by using webpack, rollup or esbuild. This will make it more complicated, or you can search a boilerplate on github.
Service worker may be inactive at any time. so that you won't be able to stay connected to the server all the time when you use socketio on service worker. Otherwise you need some hack to keep service worker alive. For example, content scripts sendMessage to it orderly and continuously. (I just imagined it this way but haven't try it yet.)

Why do we need to set up local server to run Angular JS project

I was working on a Angular JS project. Basically it is a purchased theme with Angular JS, HTML, Bootstrap etc. when i tried to run it directly on browser it is broken. but when i run the same in my local server, it works fine.
I understand the importance of setting up a local server when we work on a project with server side language like PHP, .NET. what i am really confused is, why do we need to set up local server to run javascript or any javascript frame work?
Thanks in Advance.
I would like to do these examples by access "file:///C:/TempProjects/GameOfCards/index.html#/" on local computer, but most browsers cannot access these files on local computer do to Cross Origin issues. Here a StackOverflow question and answer that describes this issue: Cross origin requests(CORS) are only supported for HTTP but it’s not cross-domain. So we need a web server
There is another way, by adding a switch in your browser(chrome in this case)-
--allow-file-access-from-files
But, I suggest, running a simple server is the best way of working with things. Hope it helps. Happy Coding.
it happened for me . and I got that , when you run a js project directly , the address of some dependencies will change . for example your index is in c://www directory . if you want to open a html file which it's address in routing is in
c://www/public/... the routing would be different . because when run on a server the www directory is running and your home directory is that . but when you run directly, your home directory is where your index file is ...

Open local html pages using http to test

I am coding a webapp and i get this kind of errors with chrome :
XMLHttpRequest cannot load file:///C:\Users\Tordah\Desktop\foobar.xml. Cross origin requests are only supported for HTTP.
&
Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load
I believe i get this error because the HTML file is accessed with file: protocol and not http: protocol which creates compatibility issues with XMLHttpRequest (That's a guess). I would like to know if there's any ways of testing my pages using http protocol only with my local machine (because only later in this project i will have access to a server, and therefore the app will only work using http, but for now i would like to be able to test it properly).
Is there any workarrounds that i could do on a local machine and that could with with the three browsers IE, Firefox and Chrome?
Thanks.
I assume that you didn't install a local server...i suggest you XAMPP, is the best for doing this kind of stuffs...
https://www.apachefriends.org/download.html
here is the url where you can download it. when you already install it, you have to copy your work into the directory
C:/xampp/htdocs/(here you paste your work)
open your browser and write in the url like this:
http://localhost:8080/(name of your work directory)/(what archive you want to see, better if it has index)
You need to install a web server. You have a bunch of different choices, but since you didn't mention an operating system, I'll suggest XAMPP from https://www.apachefriends.org/download.html
That will give you an Apache distribution containing MySQL, PHP, and Perl and will run on Windows/Mac/Linux

javascript not working on localhost

Ok so I'm lost here, frustrated and pulling my hair and out. Plus probably about to be fired or take a pay cut.
I moved Files from a development server to my local machine. The files are consistent (used diff tool), all the dependencies are there. It works for the most part. The problem is that the some of the javascript (not all) is just not working. We're using jquery and a lot of plugins for it. I've checked with the web developer plugin in firefox and all the js files are loading. I cleared the cache in both firefox and chrome multiple times to no avail. The development server is a windows server running wamp. My local machine is running ubuntu. Somebody tell me what I missed.
Download firebug as a Firefox extension and view the http request and responses.
Easiest may be from within the 'net' tab to determine if your script is making a request.
Very likely that it is a source domain issue. There are no work-around for this issue. The ajax request and the source data must be on the same domain.
It may have something to do with JavaScript's security limitations. (In certain circumstances) You can only operate on URLs or pages from the current domain, which most likely changed when you moved the files off the other server. More here.
Are you running the files via a webserver, or just opening the files directly? If it's the latter, you'll want to set up a server on your local machine for local testing, and serve the files using it. Otherwise, you'll very likely run into the domain restrictions others have mentioned above.
You may need to host the site using a local server. VS IDE has an add-on called live server. You need to set up a workspace in order for it to work. The port used on my machine was 5500.
You need to make sure any dependencies for javascript are running on your server or the javascript will not be executed. These dependencies are listed in the json file.
ex. If you require express, you need to be running node or the javascript won't execute in your web browser.
In the terminal:
node app.js
Any dependencies that are not installed and running on the server will not execute.
Are you accessing the html web pages through the webserver and not simply double clicking the file to open it?
Also if you have WebDeveloper toolbar installed the click "Disable", "Disable Javascript" and make sure "All Javascript" isn't ticked.

Categories