Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Unable to load external scripts when debugging JavaScript in VisualStudioCode because of CORS

I want to debug my client-side JavaScript code in Visual Studio Code (VSC). However, I want to avoid setting up an external live server and want to just load the files from my local drive. Because of this I created the following launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome from the file system",
            "file": "${workspaceFolder}/src/index.html"
        }
    ]
}

This executes well, when starting the debugger with F5 in VSC, Chrome opens and loads my index.html from the src folder.

However, I get the following error message when trying to import my index.js file like this <script src="./index.js" type="module" defer></script>:

Access to script at 'file:///home/matrix/odin-battleship/src/index.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

I know that this is a safety measure, which prevents websites from accessing my files. I've read about it here. However, I just want to debug my code without creating a live-server. I came across starting Chrome with the flag --allow-file-access-from-files. This question explains how to launch Chrome from launch.json with flags.

Is this the right attempt, or are there better solutions to debug your files from your local storage in VSC?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As you have mentioned, it is a security policy enforced by the browser to prevent the website owners from accessing the files on your computer.

You should start distributing this js file from any servers. That way your scheme will be http or https and the file can be served safely over to the browser.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!