Franco Tiveron
Franco Tiveron

Reputation: 2896

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?

Upvotes: 4

Views: 2660

Answers (1)

Franco Tiveron
Franco Tiveron

Reputation: 2896

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.

Upvotes: 6

Related Questions