Sui.

Post

Share your knowledge.

HaGiang.
Jul 26, 2025
Expert Q&A

How can I set it up so that user does not need to manually enable popup?

I integrated Slush wallet to my code with Sui dapp-kit SDK, it connects with the Google ZK wallet in IOS and Android browsers but when I try to interact with contract and executes a function I am getting error Failed to open new window. After I manually enable pop up for the mobile browser it works. How can I set it up so that user does not need to manually enable popup?

  • Sui
0
5
Share
Comments
.

Answers

5
Arnold.
Arnold3036
Jul 29 2025, 15:00

The error occurs due to browser popup blockers. Instead of relying on window popups, use deep linking or wallet's in-app browser for a seamless experience.

Fix (Sui dApp-Kit + Slush Wallet):

// Use `walletKit.connect()` with `preferredOpenLink` to avoid popups
import { walletKit } from "@mysten/dapp-kit";

await walletKit.connect({
  preferredOpenLink: (link) => {
    // Handle deep link (mobile) or direct navigation
    window.location.href = `slushwallet://connect?url=${encodeURIComponent(link)}`;
  },
});

Key Solutions:

  1. Deep Linking – Directly open the wallet app instead of a popup.
  2. In-App Browser – If the user is in a wallet browser (e.g., Slush in-app), avoid window.open().
  3. Fallback Logic – Detect mobile and switch to non-popup auth.

For Mobile Browsers:

// Check if it's a mobile browser
const isMobile = /Android|iPhone/i.test(navigator.userAgent);

if (isMobile) {
  // Use deep link instead of popup
  window.location.href = `slushwallet://tx?data=${txData}`;
} else {
  // Fallback to standard popup flow
  window.open(walletUrl, "_blank");
}
4
Comments
.
Evgeniy CRYPTOCOIN.
Jul 30 2025, 08:57

You can’t fully bypass browser popup restrictions for security reasons, but you can improve the UX:

  1. Pre-Request Permission (iOS/Android):

    • Trigger a harmless window.open() during initial wallet connection to "prime" the browser.
  2. Use In-App Browser (Best Fix):

    • Embed Slush Wallet’s deep link directly in your dApp (e.g., slush://connect?callback=your-app).
  3. User Guidance:

    • Show a prompt like "Enable popups for this site to sign transactions" with a help link.

Why It Happens:
Mobile browsers block window.open() unless triggered by direct user action (e.g., button click).

Workaround Code:

// Add this to your connect button handler  
function handleConnect() {  
  window.open('', '_blank'); // "Priming" popup  
  connectWallet(); // Now Slush’s popup may work  
}  

(For iOS, Safari is strict—consider a native app or WalletConnect fallback.)

3
Comments
.
Alya.
Alya-14
Jul 31 2025, 14:35

Yes — always pass a SuiClient to TransactionBlock.build() unless you’ve manually set all inputs (objects, gas, sender, etc.). The error means the SDK can’t fetch required data. Quick fix: provide the client.

3
Comments
.
BigSneh.
Jul 26 2025, 17:49

To avoid the “Failed to open new window” error when using the Slush wallet with the Sui dapp-kit SDK, especially on mobile browsers, you need to make sure your wallet interaction is triggered directly by a user gesture (like a button click). Here’s how to handle it:

  1. Trigger Wallet Calls Inside User Interaction

Browsers allow pop-ups (like wallet modals) only when triggered directly by user actions. Your code that calls signAndExecuteTransactionBlock or similar must be inside a synchronous function triggered by a button or similar user interaction.

Example:

const handleClick = async () => { const tx = new TransactionBlock(); tx.moveCall({ target: '0x::module::function' });

try { const result = await signAndExecuteTransactionBlock({ transactionBlock: tx }); console.log('Success:', result); } catch (e) { console.error('Transaction failed:', e); } };

  1. Avoid Async Delays Before Popup

Don’t insert await, setTimeout, or async fetches before the wallet popup. These break the chain of trusted user interaction, and the browser will block the popup.

Bad:

<button onClick={async () => { await fetch('/log'); // breaks the gesture trust await signAndExecuteTransactionBlock(...); }}>

Good:

<button onClick={() => { signAndExecuteTransactionBlock(...); // called immediately }}>

  1. Check for Popup Blocking

You can detect if the popup was blocked and then show instructions.

try { const popup = window.open('https://slush.sui.io/login'); if (!popup || popup.closed || typeof popup.closed === 'undefined') { alert('Please enable popups in your browser settings.'); } } catch (e) { alert('Popup blocked. Enable it manually in browser settings.'); }

  1. Educate Users

If you can’t guarantee that the wallet call is tied to a button press (e.g., automatic redirect or trigger after page load), notify users with a modal or warning to manually allow popups in their browser settings.

  1. Avoid Programmatic Wallet Calls on Load

If your code tries to connect or execute a transaction when the page loads or without user interaction, most mobile browsers (especially Safari and Chrome on Android) will block it.

2
Comments
.
290697tz.
Jul 27 2025, 06:57

To avoid the popup error, make sure all wallet interactions are triggered directly by a user action, like a button click. Avoid any delays, async calls, or timeouts before opening the wallet. Do not call the transaction logic automatically on page load or in background events. Ensure the call to the wallet happens immediately in the event handler. This is required by mobile browser security rules.

1
Comments
.

Do you know the answer?

Please log in and share it.