所以我正在开发一个通过 goo.gl 缩短 URL 的 chrome 扩展
这是我的实际代码,如果它可能有帮助:
$("#ajaxfiller").text("");
//Get URL entered
var longUrl = $("#input2").val();
longUrl = '"' + longUrl + '"';
function googlurl(url, cb) {
jsonlib.fetch({
url: 'https://www.googleapis.com/urlshortener/v1/url',
header: 'Content-Type: application/json',
// Just a static URL for shortening:
data: JSON.stringify({
longUrl: "https://google.com"
})
}, function (m) {
var result = null;
try {
result = JSON.parse(m.content).id;
if (typeof result != 'string') result = null;
} catch (e) {
result = null;
}
cb(result);
});
}
googlurl(longUrl, function (s) {
alert(s);
$("#kinchyj").show();
$("#ajaxfiller").val(s);
});
注意:当我将扩展程序加载popup.html
为常规网页时,它确实有效。
看来此错误是 Chrome 安全措施。无论如何我可以在清单中将其列入白名单吗?