Fetch API not working unless already on URL

I am trying to test a script I created with on RunKit using express, but having some issues with using it. I am quite a newbie to serverside scripting so this may be obvious…

When I have used the URL in the browser to access the Html I am sending from the RunKit server I created then if I open the console in dev tools and use the JS Fetch API to again call the same URL (to simulate doing it using JS) then I get the response as expected. However, if I open a new tab with no URL yet and try the same thing using the console then it returns only errors…

Why is this? I saw no cookies or anything like that.

Hi there,

It’s difficult to say what the issue is with any degree of certainty without seeing the actual error or the code you’re using, but it sounds like you’re running into a same-origin policy error: Same-origin policy - Web security | MDN

Hi, thanks for the response. It turns out that if you try and run a JS fetch api in browser developer tools without having loaded a page (be it the runkit initial response or any other web page) then it will not actually work… just a browser thing I guess.

So if I had built it in an app and run that it would have been fine, but using browser dev tools without previously connecting to a site does not allow for this function to work…