尽管 <all_urls> 清单许可,来自扩展的 Xhr 被阻止
Xhr from extension is blocked despite the <all_urls> manifest permission
正如我从 https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#Host_permissions 中学到的,要发出不受限制的 cors 请求,拥有主机权限就足够了,所以我的清单如下所示:
"permissions": [
"activeTab",
"proxy",
"<all_urls>"
],
我也试过使用清单中关于 csp 的密钥:
"content_security_policy": "default-src 'self' 'unsafe-inline'; script-src 'self'; object-src 'self'"
但是没有用
但是当我尝试制作 xhr 时,我仍然在控制台中看到:
内容安全策略:该页面的设置阻止了在 https://jsonplaceholder.typicode.com/posts/1(“default-src”)加载资源(使用上面的 csp 设置;使用默认 csp 我什至没有看到请求的尝试)
document.addEventListener("click", (e) => {
function sendCredentials() {
var payload = JSON.stringify({
'login': document.login.value,
'password': document.password.value
});
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == XMLHttpRequest.DONE) {
browser.runtime.sendMessage({
"type": "save_token",
"session_token": 'dummy_token'
});
}
}
xhr.open("GET", "https://jsonplaceholder.typicode.com/posts/1", true);
xhr.send();
if (e.target.id == 'submit') {
sendCredentials();
}
}
我希望在 manifest.json 中设置主机权限后,我将能够请求任何 url
我猜代码被注入了页面。对吗?
主机权限适用于从扩展程序发出的请求。将代码注入页面后,它就会从页面获得许可,CORS 通常会被阻止。
您可以将其传递回扩展程序以发出请求,然后使用消息传递将其传递回页面 API。
Firefox 似乎在声明 "we are blocking all third-party storage access requests and content blocking is enabled."
Blocked: All third-party storage access requests
您可以尝试从后台脚本或页面执行此操作。例如,它在选项页面上工作正常。
正如我从 https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#Host_permissions 中学到的,要发出不受限制的 cors 请求,拥有主机权限就足够了,所以我的清单如下所示:
"permissions": [
"activeTab",
"proxy",
"<all_urls>"
],
我也试过使用清单中关于 csp 的密钥:
"content_security_policy": "default-src 'self' 'unsafe-inline'; script-src 'self'; object-src 'self'"
但是没有用
但是当我尝试制作 xhr 时,我仍然在控制台中看到:
内容安全策略:该页面的设置阻止了在 https://jsonplaceholder.typicode.com/posts/1(“default-src”)加载资源(使用上面的 csp 设置;使用默认 csp 我什至没有看到请求的尝试)
document.addEventListener("click", (e) => {
function sendCredentials() {
var payload = JSON.stringify({
'login': document.login.value,
'password': document.password.value
});
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == XMLHttpRequest.DONE) {
browser.runtime.sendMessage({
"type": "save_token",
"session_token": 'dummy_token'
});
}
}
xhr.open("GET", "https://jsonplaceholder.typicode.com/posts/1", true);
xhr.send();
if (e.target.id == 'submit') {
sendCredentials();
}
}
我希望在 manifest.json 中设置主机权限后,我将能够请求任何 url
我猜代码被注入了页面。对吗?
主机权限适用于从扩展程序发出的请求。将代码注入页面后,它就会从页面获得许可,CORS 通常会被阻止。
您可以将其传递回扩展程序以发出请求,然后使用消息传递将其传递回页面 API。
Firefox 似乎在声明 "we are blocking all third-party storage access requests and content blocking is enabled." Blocked: All third-party storage access requests
您可以尝试从后台脚本或页面执行此操作。例如,它在选项页面上工作正常。