Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error running javascript fetch in Chrome devtools console

According to this SO post I should be able to run a fetch request from Chrome devtools console. In fact, if I click the button in the post answer, it works.

However, if I try to execute the very same code in the console, it doesn't work.

fetch('https://jsonplaceholder.typicode.com/posts/1')
  .then(res => res.json())
  .then(console.log)

enter image description here

What's missing?

like image 553
Franco Tiveron Avatar asked Oct 25 '25 05:10

Franco Tiveron


1 Answers

Don't know why, however it depends on the current domain the browser is:

Home page:

enter image description here

After browsing a page (whatever page):

enter image description here

My guess would be that in the first case there is not an established source domain, but a better error description would help.

like image 159
Franco Tiveron Avatar answered Oct 26 '25 17:10

Franco Tiveron