Post
Share your knowledge.
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
Answers
5The 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:
- Deep Linking – Directly open the wallet app instead of a popup.
- In-App Browser – If the user is in a wallet browser (e.g., Slush in-app), avoid
window.open(). - 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");
}
You can’t fully bypass browser popup restrictions for security reasons, but you can improve the UX:
-
Pre-Request Permission (iOS/Android):
- Trigger a harmless
window.open()during initial wallet connection to "prime" the browser.
- Trigger a harmless
-
Use In-App Browser (Best Fix):
- Embed Slush Wallet’s deep link directly in your dApp (e.g.,
slush://connect?callback=your-app).
- Embed Slush Wallet’s deep link directly in your dApp (e.g.,
-
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.)
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.
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:
- 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); } };
- 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 }}>
- 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.'); }
- 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.
- 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.
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.
Do you know the answer?
Please log in and share it.
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.
- How to Maximize Profit Holding SUI: Sui Staking vs Liquid Staking616
- Why does BCS require exact field order for deserialization when Move structs have named fields?65
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution55
- Sui Move Error - Unable to process transaction No valid gas coins found for the transaction419
- Sui Transaction Failing: Objects Reserved for Another Transaction410