I'm building a javascript website its a simple snake game but whenever I launch the index.html file it gives me this error
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.
my js files are:
import { update as updateSnake, draw as drawSnake, SNAKE_SPEED } from './snake.js'
let lastRenderTime = 0
const gameBoard = document.getElementById('game-board')
function main(currentTime){
window.requestAnimationFrame(main)
const secondsSinceLastRender = (currentTime - lastRenderTime)/1000
if ( secondsSinceLastRender < 1 / SNAKE_SPEED) return
lastRenderTime = currentTime
update()
draw()
}
window.requestAnimationFrame(main)
function update(){
updateSnake()
}
function draw (){
drawSnake(gameBoard)
}
the other file:
export const SNAKE_SPEED =1
const snakeBody = [{ x: 11, y:11 },
{ x: 10, y: 11 },
{ x: 12, y: 11 }
]
export function update(){
// console.log('update snake')
}
export function draw (gameBoard){
snakeBody.forEach(segment => {
const snakeElement = document.createElement('div')
snakeElement.style.gridRowStart = segement.x
snakeElement.style.gridColumnStart = segement.y
snakeElement.classList.add('snake')
gameBoard.appendChild(snakeElement)
})
}
I have looked up all other solutions but none has worked for me I used firefox and the same problem appeared