0

我有一个 chrome 扩展,可以将我的书签输出到控制台。但我不想输出,而是想使用内容脚本将所有这些书签发送到我的远程服务器。

我怎样才能做到这一点 ?manifest.json 文件中是否包含任何特殊权限?

function getBookmarks()
{
     ........ (*get the bookmarks and store them in an array BookArray)
    var xhr = new XMLHttpRequest();
   xhr.open("GET", "server_domain", true);
   xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
        (*send the entire array to the server *)
 }
}
xhr.send();
4

1 回答 1

0

您可以使用 XMLHttpRequest 将数据发布到您的服务器。

您需要添加的唯一清单字段是permissions,以启用跨域 XMLHttpRequest

请注意,从 Chrome 13 开始,内容脚本能够执行跨域请求。

今天稳定的 Chrome 版本是 17,但是,如果你需要在 13 版本之前向后兼容,你需要在你的 background.html 中实现你的 XMLHttpRequest 并做一些额外的代码来使它工作。

于 2012-03-09T12:03:17.147 回答