Skip to content

Commit fbe404d

Browse files
committed
fix: sleep a second before downloading
1 parent 44424cd commit fbe404d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

injected/src/features/autofill-import.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,18 @@ export default class AutofillImport extends ActionExecutorMixin(ContentFeature)
482482
}
483483
}
484484

485+
get dbpActions() {
486+
return this.getFeatureSetting('actions')?.[0] ?? [];
487+
}
488+
485489
/**
486490
* @param {Location} location
487491
*
488492
*/
489493
async handleLocation(location) {
490494
const { pathname } = location;
491-
if (this.getFeatureSetting('actions')[0].length > 0) {
495+
const dbpActions = this.dbpActions;
496+
if (dbpActions.length > 0) {
492497
if (this.#processingBookmark) {
493498
return;
494499
}
@@ -575,8 +580,12 @@ export default class AutofillImport extends ActionExecutorMixin(ContentFeature)
575580
}
576581

577582
/** Bookmark import code */
578-
downloadData() {
583+
async downloadData() {
584+
// sleep for a second, sometimes download link is not yet available
585+
await new Promise((resolve) => setTimeout(resolve, 1000));
586+
579587
const userId = document.querySelector(this.getFeatureSetting('selectors').userIdLink)?.getAttribute('href')?.split('&user=')[1];
588+
await this.runWithRetry(() => document.querySelector(`a[href="./manage/archive/${this.#exportId}"]`), 15, 2000, 'linear');
580589
const downloadURL = `${TAKEOUT_DOWNLOAD_URL_BASE}?j=${this.#exportId}&i=0&user=${userId}`;
581590
window.location.href = downloadURL;
582591
}
@@ -590,15 +599,15 @@ export default class AutofillImport extends ActionExecutorMixin(ContentFeature)
590599

591600
async handleBookmarkImportPath(pathname) {
592601
if (pathname === '/' && !this.#isBookmarkModalVisible) {
593-
for (const action of this.getFeatureSetting('actions')[0]) {
602+
for (const action of this.dbpActions) {
594603
// Before clicking on the manage button, we need to store the export id
595604
if (action.id === 'manage-button-click') {
596605
await this.storeExportId();
597606
}
598607

599608
await this.processActionAndNotify(action, {}, this.retryConfig);
600609
}
601-
this.downloadData();
610+
await this.downloadData();
602611
}
603612
}
604613

0 commit comments

Comments
 (0)