Skip to content

Commit 981fd3b

Browse files
committed
fix: improve navigation handling
Signed-off-by: kryptocodes <srivatsantb@gmail.com>
1 parent 36c66c0 commit 981fd3b

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

src/Reclaim.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,11 +1283,25 @@ export class ReclaimProofRequest {
12831283
}
12841284

12851285
if (mode === 'portal') {
1286-
// Portal mode: open in new tab
1286+
// Open blank tab synchronously to preserve click activation (avoids popup blocker)
12871287
const portalUrl = this.customSharePageUrl ?? 'https://portal.reclaimprotocol.org';
1288+
const newTab = window.open('about:blank', '_blank');
12881289
const link = await createLinkWithTemplateData(templateData, portalUrl);
12891290
logger.info('Opening portal in new tab: ' + link);
1290-
window.open(link, '_blank');
1291+
if (newTab) {
1292+
newTab.location = link;
1293+
// Verify navigation actually happened; close blank tab if it didn't
1294+
setTimeout(() => {
1295+
try {
1296+
if (newTab.location.href === 'about:blank') {
1297+
newTab.close();
1298+
window.open(link, '_blank');
1299+
}
1300+
} catch (_) {
1301+
// Cross-origin after navigation means it worked
1302+
}
1303+
}, 500);
1304+
}
12911305
} else {
12921306
// App mode: QR code modal with share page URL
12931307
logger.info('Showing QR code modal with share page URL');
@@ -1305,11 +1319,24 @@ export class ReclaimProofRequest {
13051319
await this.redirectToInstantApp(options);
13061320
}
13071321
} else {
1308-
// Portal mode on mobile: open portal URL in new tab
1322+
// Portal mode on mobile: open blank tab synchronously, then navigate
13091323
const portalUrl = this.customSharePageUrl ?? 'https://portal.reclaimprotocol.org';
1324+
const newTab = window.open('about:blank', '_blank');
13101325
const link = await createLinkWithTemplateData(templateData, portalUrl);
1311-
logger.info('Opening portal in new tab: ' + link);
1312-
window.open(link, '_blank');
1326+
logger.info('Opening portal on mobile: ' + link);
1327+
if (newTab) {
1328+
newTab.location = link;
1329+
setTimeout(() => {
1330+
try {
1331+
if (newTab.location.href === 'about:blank') {
1332+
newTab.close();
1333+
window.open(link, '_blank');
1334+
}
1335+
} catch (_) {
1336+
// Cross-origin after navigation means it worked
1337+
}
1338+
}, 500);
1339+
}
13131340
}
13141341
}
13151342
} catch (error) {

0 commit comments

Comments
 (0)