4

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?

7
  • 1
    May be internet connection. Search https://jsonplaceholder.typicode.com/posts/1 in browser search bar and validate the response Commented Jul 20, 2021 at 2: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... Commented Jul 20, 2021 at 2:35
  • @brk It works on the browser Commented Jul 20, 2021 at 2:39
  • @AlexanderNied There is no context. I am just doing what in the picture Commented Jul 20, 2021 at 2: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. Commented Jul 20, 2021 at 2:43

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Lol nice hint. Somehow it resolves problem
Thanks, this solved my issue. If I had to guess it is to do with https. When no website is open it is effectively making https request from a non-https website hence it gets rejected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.