javascript - Sending URLs to server from Chrome Extension background.js -
i'm building simple chrome extension url of each of users browser pages when opened , send server. can url appear in alert box, ajax returning blank value database. alerts work fine though(?)
any ideas/thoughts? see script below..
popup.html:
<html> <head> <title>facebook connect chrome extension</title> <script type="text/javascript" src="index.js"></script> </head> <body> <h1>facebook connect chrome extension</h1> <p><a target="_blank"href="https://www.facebook.com/dialog/oauth?client_id=my-app- id&response_type=token&scope=email&redirect_uri=http://www.facebook.com">facebook connect</a></p> </body> </html>
updated background.js:
chrome.tabs.onupdated.addlistener(function (tabid, changeinfo, tab) { if (changeinfo != undefined) { var http = new xmlhttprequest(); http.open("post", "http://ec2-52-89-93-50.us-west-2.compute.amazonaws.com/phpindex.php", true); sendme = changeinfo.url http.send(sendme); } alert(sendme); });
updated manifest.json:
{ "name": "example", "version": "1.0", "description": "example"
"browser_action": { "default_popup": "popup.html", "default_icon":"icon.png" }, "background": { "scripts": ["background.js"] }, "manifest_version":2, "permissions": [ "tabs", "http://*.facebook.com/*", "http://my_server/*", "http://*/*", "https://*/*", "<all_urls>" ] }
as per tabs.onactivated documentation:
note tab's url may not set @ time event fired, can listen onupdated events notified when url set.
use chrome.tabs.onupdated
listener callback post url server.
Comments
Post a Comment