mirror of
https://github.com/bitwarden/desktop.git
synced 2024-10-04 04:58:05 +02: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);
|
||||
}
|
||||
|
||||
autofillService.doAutoFill(login, pageDetails, false).then(function () {
|
||||
autofillService.doAutoFill(login, pageDetails, false).then(function (totpCode) {
|
||||
$analytics.eventTrack('Autofilled');
|
||||
if (totpCode && utilsService.isFirefox()) {
|
||||
utilsService.copyToClipboard(totpCode, document);
|
||||
}
|
||||
$window.close();
|
||||
}, function () {
|
||||
$analytics.eventTrack('Autofilled Error');
|
||||
|
@ -260,13 +260,15 @@ function initAutofill() {
|
||||
if (code) {
|
||||
self.utilsService.copyToClipboard(code);
|
||||
}
|
||||
|
||||
return code;
|
||||
});
|
||||
}
|
||||
|
||||
if (didAutofill) {
|
||||
if (totpPromise) {
|
||||
totpPromise.then(function () {
|
||||
deferred.resolve();
|
||||
totpPromise.then(function (totpCode) {
|
||||
deferred.resolve(totpCode);
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
@ -200,29 +200,30 @@ function initUtilsService() {
|
||||
return null;
|
||||
};
|
||||
|
||||
UtilsService.prototype.copyToClipboard = function (text) {
|
||||
UtilsService.prototype.copyToClipboard = function (text, doc) {
|
||||
doc = doc || document;
|
||||
if (window.clipboardData && window.clipboardData.setData) {
|
||||
// IE specific code path to prevent textarea being shown while dialog is visible.
|
||||
return clipboardData.setData('Text', text);
|
||||
}
|
||||
else if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
|
||||
var textarea = document.createElement('textarea');
|
||||
else if (doc.queryCommandSupported && doc.queryCommandSupported('copy')) {
|
||||
var textarea = doc.createElement('textarea');
|
||||
textarea.textContent = text;
|
||||
// Prevent scrolling to bottom of page in MS Edge.
|
||||
textarea.style.position = 'fixed';
|
||||
document.body.appendChild(textarea);
|
||||
doc.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
|
||||
try {
|
||||
// Security exception may be thrown by some browsers.
|
||||
return document.execCommand('copy');
|
||||
return doc.execCommand('copy');
|
||||
}
|
||||
catch (ex) {
|
||||
console.warn('Copy to clipboard failed.', ex);
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
document.body.removeChild(textarea);
|
||||
doc.body.removeChild(textarea);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user