mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 14:23:32 +00:00
Added autofill support for iframed login forms. #20
This commit is contained in:
@@ -26,7 +26,11 @@ chrome.commands.onCommand.addListener(function (command) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var loadMenuRan = false;
|
var loadMenuRan = false,
|
||||||
|
siteToAutoFill = null,
|
||||||
|
pageDetailsToAutoFill = [],
|
||||||
|
autofillTimeout = null;
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
||||||
if (msg.command === 'loggedOut' || msg.command === 'loggedIn' || msg.command === 'unlocked' || msg.command === 'locked') {
|
if (msg.command === 'loggedOut' || msg.command === 'loggedIn' || msg.command === 'unlocked' || msg.command === 'locked') {
|
||||||
if (loadMenuRan) {
|
if (loadMenuRan) {
|
||||||
@@ -51,6 +55,11 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
|||||||
else if (msg.command === 'bgCloseOverlayPopup') {
|
else if (msg.command === 'bgCloseOverlayPopup') {
|
||||||
messageCurrentTab('closeOverlayPopup');
|
messageCurrentTab('closeOverlayPopup');
|
||||||
}
|
}
|
||||||
|
else if (msg.command === 'collectPageDetailsResponse') {
|
||||||
|
clearTimeout(autofillTimeout);
|
||||||
|
pageDetailsToAutoFill.push({ frameId: sender.frameId, tabId: msg.tabId, details: msg.details });
|
||||||
|
autofillTimeout = setTimeout(autofillPage, 300);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setIcon();
|
setIcon();
|
||||||
@@ -259,7 +268,7 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) {
|
|||||||
hitType: 'event',
|
hitType: 'event',
|
||||||
eventAction: 'Autofilled From Context Menu'
|
eventAction: 'Autofilled From Context Menu'
|
||||||
});
|
});
|
||||||
autofillPage(sites[i]);
|
startAutofillPage(sites[i]);
|
||||||
}
|
}
|
||||||
else if (info.parentMenuItemId === 'copy-username') {
|
else if (info.parentMenuItemId === 'copy-username') {
|
||||||
ga('send', {
|
ga('send', {
|
||||||
@@ -310,7 +319,8 @@ function messageCurrentTab(command, data) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function autofillPage(site) {
|
function startAutofillPage(site) {
|
||||||
|
siteToAutoFill = site;
|
||||||
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
||||||
var tabId = null;
|
var tabId = null;
|
||||||
if (tabs.length > 0) {
|
if (tabs.length > 0) {
|
||||||
@@ -324,21 +334,49 @@ function autofillPage(site) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs.sendMessage(tabId, { command: 'collectPageDetails' }, function (pageDetails) {
|
chrome.tabs.sendMessage(tabId, { command: 'collectPageDetails', tabId: tabId }, function () { });
|
||||||
var fillScript = null;
|
});
|
||||||
if (site && pageDetails) {
|
}
|
||||||
fillScript = autofillService.generateFillScript(pageDetails, site.username, site.password);
|
|
||||||
|
function autofillPage() {
|
||||||
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
||||||
|
var tabId = null;
|
||||||
|
if (tabs.length > 0) {
|
||||||
|
tabId = tabs[0].id;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tabId && fillScript && fillScript.script) {
|
if (!tabId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fillScript = null;
|
||||||
|
if (siteToAutoFill && pageDetailsToAutoFill && pageDetailsToAutoFill.length) {
|
||||||
|
for (var i = 0; i < pageDetailsToAutoFill.length; i++) {
|
||||||
|
// make sure we're still on correct tab
|
||||||
|
if (pageDetailsToAutoFill[i].tabId != tabId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fillScript = autofillService.generateFillScript(pageDetailsToAutoFill[i].details, siteToAutoFill.username,
|
||||||
|
siteToAutoFill.password);
|
||||||
|
if (tabId && fillScript && fillScript.script && fillScript.script.length) {
|
||||||
chrome.tabs.sendMessage(tabId, {
|
chrome.tabs.sendMessage(tabId, {
|
||||||
command: 'fillForm',
|
command: 'fillForm',
|
||||||
fillScript: fillScript
|
fillScript: fillScript
|
||||||
|
}, {
|
||||||
|
frameId: pageDetailsToAutoFill[i].frameId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// reset
|
||||||
|
siteToAutoFill = null;
|
||||||
|
pageDetailsToAutoFill = [];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortSites(sites) {
|
function sortSites(sites) {
|
||||||
|
|||||||
@@ -81,7 +81,15 @@
|
|||||||
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
||||||
if (msg.command === 'collectPageDetails') {
|
if (msg.command === 'collectPageDetails') {
|
||||||
var pageDetails = collect(document);
|
var pageDetails = collect(document);
|
||||||
sendResponse(JSON.parse(pageDetails));
|
var pageDetailsObj = JSON.parse(pageDetails);
|
||||||
|
console.log(pageDetailsObj);
|
||||||
|
//sendResponse(pageDetailsObj);
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
command: 'collectPageDetailsResponse',
|
||||||
|
tabId: msg.tabId,
|
||||||
|
details: pageDetailsObj
|
||||||
|
});
|
||||||
|
sendResponse();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (msg.command === 'fillForm') {
|
else if (msg.command === 'fillForm') {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
},
|
},
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
|
"all_frames": true,
|
||||||
"js": [ "content/autoFill.js" ],
|
"js": [ "content/autoFill.js" ],
|
||||||
"matches": [ "http://*/*", "https://*/*", "file:///*" ],
|
"matches": [ "http://*/*", "https://*/*", "file:///*" ],
|
||||||
"run_at": "document_start"
|
"run_at": "document_start"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ angular
|
|||||||
$analytics, i18nService) {
|
$analytics, i18nService) {
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
|
|
||||||
var pageDetails = null,
|
var pageDetails = [],
|
||||||
tabId = null,
|
tabId = null,
|
||||||
url = null,
|
url = null,
|
||||||
domain = null,
|
domain = null,
|
||||||
@@ -32,8 +32,7 @@ angular
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs.sendMessage(tabId, { command: 'collectPageDetails' }, function (details) {
|
chrome.tabs.sendMessage(tabId, { command: 'collectPageDetails', tabId: tabId }, function () {
|
||||||
pageDetails = details;
|
|
||||||
canAutofill = true;
|
canAutofill = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -71,21 +70,31 @@ angular
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.fillSite = function (site) {
|
$scope.fillSite = function (site) {
|
||||||
var fillScript = null;
|
var didAutofill = false;
|
||||||
if (site && canAutofill && pageDetails) {
|
|
||||||
fillScript = autofillService.generateFillScript(pageDetails, site.username, site.password);
|
if (site && canAutofill && pageDetails && pageDetails.length) {
|
||||||
|
for (var i = 0; i < pageDetails.length; i++) {
|
||||||
|
if (pageDetails[i].tabId != tabId) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fillScript = autofillService.generateFillScript(pageDetails[i].details, site.username, site.password);
|
||||||
if (tabId && fillScript && fillScript.script && fillScript.script.length) {
|
if (tabId && fillScript && fillScript.script && fillScript.script.length) {
|
||||||
|
didAutofill = true;
|
||||||
$analytics.eventTrack('Autofilled');
|
$analytics.eventTrack('Autofilled');
|
||||||
chrome.tabs.sendMessage(tabId, {
|
chrome.tabs.sendMessage(tabId, {
|
||||||
command: 'fillForm',
|
command: 'fillForm',
|
||||||
fillScript: fillScript
|
fillScript: fillScript
|
||||||
|
}, {
|
||||||
|
frameId: pageDetails[i].frameId
|
||||||
}, function () {
|
}, function () {
|
||||||
$window.close();
|
$window.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!didAutofill) {
|
||||||
$analytics.eventTrack('Autofilled Error');
|
$analytics.eventTrack('Autofilled Error');
|
||||||
toastr.error(i18nService.autofillError);
|
toastr.error(i18nService.autofillError);
|
||||||
}
|
}
|
||||||
@@ -106,4 +115,8 @@ angular
|
|||||||
setTimeout(loadVault, 500);
|
setTimeout(loadVault, 500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.$on('collectPageDetailsResponse', function (event, details) {
|
||||||
|
pageDetails.push(details);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,5 +29,12 @@ angular
|
|||||||
$state.go('home');
|
$state.go('home');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else if (msg.command === 'collectPageDetailsResponse') {
|
||||||
|
$scope.$broadcast('collectPageDetailsResponse', {
|
||||||
|
frameId: sender.frameId,
|
||||||
|
tabId: msg.tabId,
|
||||||
|
details: msg.details
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user