Javascript 控制台显示CSP错误,因为位置更改时chrome扩展重新加载blob文件
我编写了一个chrome扩展,在github页面上插入一个图像,图像的src是根据XMLHttpRequest的响应(blob类型)创建的,如下所示:Javascript 控制台显示CSP错误,因为位置更改时chrome扩展重新加载blob文件,javascript,google-chrome,github,google-chrome-extension,xmlhttprequest,Javascript,Google Chrome,Github,Google Chrome Extension,Xmlhttprequest,我编写了一个chrome扩展,在github页面上插入一个图像,图像的src是根据XMLHttpRequest的响应(blob类型)创建的,如下所示: let xhr = new XMLHttpRequest(); let badgeUrl = `https://api.travis-ci.org${project}.svg`; xhr.open('GET', badgeUrl, true); xhr.responseType = 'blob'; xhr.onreadystate
let xhr = new XMLHttpRequest();
let badgeUrl = `https://api.travis-ci.org${project}.svg`;
xhr.open('GET', badgeUrl, true);
xhr.responseType = 'blob';
xhr.onreadystatechange = () => {
if (xhr.readyState == XMLHttpRequest.DONE) {
const img = $("<img alt='build status'></img>");
img.attr('src', window.URL.createObjectURL(xhr.response));
img.on('load', () => {
const link = $(`<a class='travis-ci' href='https://travis-ci.org${project}'></a>`);
link.append(img);
link.appendTo($(el));
});
}
};
xhr.send();
"permissions": [
"https://api.travis-ci.org/"
],
"content_security_policy": "script-src 'self' https://github.com; object-src 'self'",
"content_scripts": [ {
"js": [ "bundle.js"],
"matches": [ "https://github.com/*" ],
"run_at": "document_idle"
} ]
以下是截图:
错误量等于上一页中插入的blob图像数
事实上,它对这个扩展的功能没有影响,但是我希望在没有这些恼人的错误日志的情况下使控制台更干净。有人对此有想法吗
顺便说一句,我已经在清单文件的权限中添加了类似“api.travis ci.org”的链接,如下所示:
let xhr = new XMLHttpRequest();
let badgeUrl = `https://api.travis-ci.org${project}.svg`;
xhr.open('GET', badgeUrl, true);
xhr.responseType = 'blob';
xhr.onreadystatechange = () => {
if (xhr.readyState == XMLHttpRequest.DONE) {
const img = $("<img alt='build status'></img>");
img.attr('src', window.URL.createObjectURL(xhr.response));
img.on('load', () => {
const link = $(`<a class='travis-ci' href='https://travis-ci.org${project}'></a>`);
link.append(img);
link.appendTo($(el));
});
}
};
xhr.send();
"permissions": [
"https://api.travis-ci.org/"
],
"content_security_policy": "script-src 'self' https://github.com; object-src 'self'",
"content_scripts": [ {
"js": [ "bundle.js"],
"matches": [ "https://github.com/*" ],
"run_at": "document_idle"
} ]
在
标记中编写svg内容,就像github本身一样。@wOxxOm感谢您的建议,但它似乎与html标记类型无关。但我使用另一种解决方案来解决这个问题:只需在本地保存这些图像。