【问题标题】:XMLHttpRequest cross-domain in Firefox addon extensionFirefox 插件扩展中的 XMLHttpRequest 跨域
【发布时间】:2018-01-13 22:54:24
【问题描述】:

我正在开发插件 chrome 和 firefox。

我的问题只出现在 Firefox 上,而不出现在 chrome 上。

我想在 domain2.com 的选项卡中创建一个带有 url domain1.com 的 XMLHttpRequest(不在后台脚本中)

var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function(event) {
    if (this.readyState === XMLHttpRequest.DONE) {
        if (this.status === 200) {
            console.log("Answer: %s", this.responseText);
        } else {
            console.log("Answer status: %d (%s)", this.status, this.statusText);
        }
    }
};  
xmlHttp.open("GET", theUrl, true);
xmlHttp.send(null);

在 chrome 中我得到 200

但 Firefox 不执行请求(应答状态:0 ())

如果我将 domain1.com 替换为 domain2.com,它就在 firefox 上运行

在我的 content_scripts 匹配中,我添加了 domain1.com 和 domain2.com

感谢您的帮助!

【问题讨论】:

    标签: javascript firefox xmlhttprequest firefox-addon firefox-addon-sdk


    【解决方案1】:

    chrome和firefox的区别: 在 Firefox 中我们需要添加

    "permissions": [
    "activeTab",
    "storage",
    "*://*.domain1.com/*"
    

    除了火狐上的两个 chrome 中的匹配项

      "content_scripts": [
    {
      "matches": [
        "*://*.domain2.com/*",
        "*://*.domain1.com/*"
      ]
    

    【讨论】:

      猜你喜欢
      • 2012-03-14
      • 1970-01-01
      • 2011-06-08
      • 2016-09-02
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      相关资源
      最近更新 更多