I am doing a Firefox WebExtension add-on. Here's what should happen:
- The user clicks the browser icon on ANY page.
- JavaScript is running, collecting information from the page.
- Information is sent to my server using
XMLHttpRequest
This is what the Chrome extension does. However, I cannot get this to work with the Firefox add-in. JavaScript is entered and executed because I see alert() , which I set at the end of the script. However, my server is not receiving a call. The Firefox debugger does not show an attempt to network activity and does not show any errors.
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!");
user984003
source share