mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
copy totp to clipboard from popup document in ff
This commit is contained in:
parent
5089cbded6
commit
eace0f32f0
@ -72,8 +72,11 @@ angular
|
|||||||
toastr.error(i18nService.autofillError);
|
toastr.error(i18nService.autofillError);
|
||||||
}
|
}
|
||||||
|
|
||||||
autofillService.doAutoFill(login, pageDetails, false).then(function () {
|
autofillService.doAutoFill(login, pageDetails, false).then(function (totpCode) {
|
||||||
$analytics.eventTrack('Autofilled');
|
$analytics.eventTrack('Autofilled');
|
||||||
|
if (totpCode && utilsService.isFirefox()) {
|
||||||
|
utilsService.copyToClipboard(totpCode, document);
|
||||||
|
}
|
||||||
$window.close();
|
$window.close();
|
||||||
}, function () {
|
}, function () {
|
||||||
$analytics.eventTrack('Autofilled Error');
|
$analytics.eventTrack('Autofilled Error');
|
||||||
|
@ -260,13 +260,15 @@ function initAutofill() {
|
|||||||
if (code) {
|
if (code) {
|
||||||
self.utilsService.copyToClipboard(code);
|
self.utilsService.copyToClipboard(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (didAutofill) {
|
if (didAutofill) {
|
||||||
if (totpPromise) {
|
if (totpPromise) {
|
||||||
totpPromise.then(function () {
|
totpPromise.then(function (totpCode) {
|
||||||
deferred.resolve();
|
deferred.resolve(totpCode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -200,29 +200,30 @@ function initUtilsService() {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
UtilsService.prototype.copyToClipboard = function (text) {
|
UtilsService.prototype.copyToClipboard = function (text, doc) {
|
||||||
|
doc = doc || document;
|
||||||
if (window.clipboardData && window.clipboardData.setData) {
|
if (window.clipboardData && window.clipboardData.setData) {
|
||||||
// IE specific code path to prevent textarea being shown while dialog is visible.
|
// IE specific code path to prevent textarea being shown while dialog is visible.
|
||||||
return clipboardData.setData('Text', text);
|
return clipboardData.setData('Text', text);
|
||||||
}
|
}
|
||||||
else if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
|
else if (doc.queryCommandSupported && doc.queryCommandSupported('copy')) {
|
||||||
var textarea = document.createElement('textarea');
|
var textarea = doc.createElement('textarea');
|
||||||
textarea.textContent = text;
|
textarea.textContent = text;
|
||||||
// Prevent scrolling to bottom of page in MS Edge.
|
// Prevent scrolling to bottom of page in MS Edge.
|
||||||
textarea.style.position = 'fixed';
|
textarea.style.position = 'fixed';
|
||||||
document.body.appendChild(textarea);
|
doc.body.appendChild(textarea);
|
||||||
textarea.select();
|
textarea.select();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Security exception may be thrown by some browsers.
|
// Security exception may be thrown by some browsers.
|
||||||
return document.execCommand('copy');
|
return doc.execCommand('copy');
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
console.warn('Copy to clipboard failed.', ex);
|
console.warn('Copy to clipboard failed.', ex);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
document.body.removeChild(textarea);
|
doc.body.removeChild(textarea);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user