If you know the redirect URL, you can parse it using the google.* API provided for extensions.
(Assume Facebook Desktop Flow , where the success URL is https://www.facebook.com/connect/login_success.html ). You need to add tabs and URLs to your permissions - for example:
"permissions": [ "tabs", "https://facebook.com/connect/*" ]
When the user presses the login / authorization button, you need to perform two steps:
Step 1
Add a listener to the Updates tab that view all tabs for success URLs:
chrome.tabs.onUpdated.addListener(function() { var lis = this; chrome.tabs.getAllInWindow(null, function(tabs) { for (var i = 0; i < tabs.length; i++) { if (tabs[i].url.indexOf("https://www.facebook.com/connect/login_success.html") == 0) { var token = tabs[i].url.match(/[\\?&#]auth_token=([^&#])*/i) chrome.tabs.onUpdated.removeListener(lis); return; } } }); });
Step 2
Redirect user to OAUTH page:
chrome.tabs.create( { 'url': "https://www.facebook.com/dialog/oauth?client_id=client_id>&redirect_uri=https://www.facebook.com/connect/login_success.html" }, null);
source share