javascript - fetch() 和 XMLHttpRequest GET 不适用于 Chrome 扩展
问题描述
我开发了一个用户脚本,它工作得非常好。但是,我最近将其转换为 Chrome 扩展程序 - 部分有效。对于 Chrome 扩展程序,唯一不起作用的是fetch()
和XMLHttpRequest GET
.
控制台中没有错误,我确保在清单中包含我试图请求的 URL。
这是我的清单:
{
"manifest_version": 2,
"name": "WallpaperUI",
"version": "0.23",
"description": "Customize your Steam Profile more effectively.",
"icons": { "128": "UILogo.png" },
"content_scripts": [
{
"matches": ["https://steamcommunity.com/id/*","https://steamcommunity.com/profiles/*"],
"js": ["jquery-3.2.1.min.js", "WallpaperUI.user.js"]
}
],
"permissions": [
"https://steamcommunity.com/*",
"activeTab"
]
}
还有我的 JS:
fetch('https://steamcommunity.com/sharedfiles/filedetails/?id=XXXXXXXXXX')
.then(function(response) {
return response.text();
})
.then(function(text) {
console.log('Request successful');
parseHTML(text);
})
.catch(function(error) {
console.log('Request failed', error);
});
解决方案
推荐阅读
- reactjs - 使用共享反应库在同一页面中呈现多个 webpack 入口点
- typescript - 需要帮助修复或抑制此 tslint 错误:TS2742
- sql - 如何在子查询上使用聚合函数?
- ios - Alamofire+Combine:如何从 AFError 中获取自定义错误类型
- kubernetes - 使用 kubernetes hostPath 时未在容器内获取已安装的主机文件的内容
- java - 如何设置 sbt 以使用 java 14 预览功能
- java - 如何将数组值添加到第二个组合框模型项中,从第一个组合框选定项中获取数组名称?
- python - 无法使用opencv从图像制作视频
- shopify - 在 Unbounce 上的 shopify 登陆页面,这将允许访问者将产品添加到购物车
- python - 使用 NLTK Python 对推文进行分类