[英]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.根据this SO post,我应该能够从Chrome devtools控制台运行获取请求。 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)
What's missing?缺少了什么?
Don't know why, however it depends on the current domain the browser is:不知道为什么,但这取决于浏览器的当前域:
Home page:主页:
After browsing a page (whatever page):浏览页面后(任何页面):
My guess would be that in the first case there is not an established source domain, but a better error description would help.我的猜测是,在第一种情况下,没有已建立的源域,但更好的错误描述会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.