Firefox WebExtension: Make XMLHttpRequest
I'm making a Firefox WebExtension add-on. Here's what should happen:
XMLHttpRequest
This is what my Chrome extension does. However, I cannot get this to work with the Firefox add-on. The JavaScript is injected and executed because I do see the alert()
, which I have put at the end of the script. However, no call is made to my server. The Firefox debugger shows no attempted network activity, nor does it show any error.
Manifest:
{
"manifest_version": 2,
"name": "my_name",
"version": "1.0",
"description": "My description",
"icons": {
"48": "icons/my_icon.png"
},
"permissions": [
"activeTab"
],
"browser_action": {
"default_icon": "icons/some_icon.png",
"default_title": "My Name"
},
"background": {
"scripts": ["background.js"]
}
}
background.js:
browser.browserAction.onClicked.addListener(function(tab) {
browser.tabs.executeScript(null, {file:"content_script.js"});
});
content_script.js:
var xmlHttp=new XMLHttpRequest();
xmlHttp.open("POST", "https://www.my_site.org",true);
var formData = new FormData();
formData.append("my_var", "my_var");
xmlHttp.send(formData);
alert("I do get here!");
您需要将该URL添加到manifest.json
permissions