firefox OS app,CORS in Firefox os app

扶醉桌前 提交于 2019-12-06 13:42:23

First change your manifest to have the following fields (the type one gets forgotten by people):

"type": "privileged", 
"permissions": {
    "systemXHR" : {}
}

Second, move all your JavaScript code to a separate JS file. Because it's not allowed to have inline tags in a privileged application.

Third use the mozSystem constructor like raidendev said:

var xhr = new XMLHttpRequest({ mozSystem: true });

To perform cross-domain http request from Firefox OS app you need to set permission systemXHR in app's manifest:

 "permissions": {
     "systemXHR" : {}
 }

and create XMLHttpRequest with property mozSystem set to true:

var xhr = new XMLHttpRequest({ mozSystem: true });

Also, for any cases where XMLHttpRequest is not applicable, you can use TCP Socket API.

var socket = navigator.mozTCPSocket.open('localhost', 80);

socket.ondata = function (event) {
  if (typeof event.data === 'string') {
    console.log('Get a string: ' + event.data);
  } else {
    console.log('Get a Uint8Array');
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!