3

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?

Phil
  • 157,677
  • 23
  • 242
  • 245
Franco Tiveron
  • 2,364
  • 18
  • 34
  • 1
    May be internet connection. Search `https://jsonplaceholder.typicode.com/posts/1` in browser search bar and validate the response – brk Jul 20 '21 at 02:34
  • 1
    I can't reproduce this-- I'm able to run this from my console and get a response. You may probably need to provide more context/information... – Alexander Nied Jul 20 '21 at 02:35
  • @brk It works on the browser – Franco Tiveron Jul 20 '21 at 02:39
  • @AlexanderNied There is no context. I am just doing what in the picture – Franco Tiveron Jul 20 '21 at 02:40
  • @FrancoTiveron - works in the console here too (from melbourne, australia) – enhzflep Jul 20 '21 at 02:40
  • 2
    Are you behind a VPN? Are you on an enterprise machine that might have security software installed? What site are you on when you are running this in the console? Is this Windows, MacOs, or Ubuntu? Do you have any browser plugins installed, perhaps any specific to the devtools? I'm just looking for anything that could be causing this because I cannot reproduce the issue. – Alexander Nied Jul 20 '21 at 02:43
  • Any ideas on what I could look at? – Franco Tiveron Jul 20 '21 at 02:44

1 Answers1

3

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.

Franco Tiveron
  • 2,364
  • 18
  • 34