FB Messenger机器人对话场景下如何设置默认浏览器打开URL而非内置浏览器
Hey there, I’ve dealt with this exact frustration before—switching between Messenger’s clunky built-in browser and your default one is such a hassle when navigating bot-guided flows and web content. Here’s how to fix it smoothly:
Core Fix: Use Button Templates with messenger_extensions: false
Don’t just drop plain text links in your bot messages. Instead, use Messenger’s Button Template (or Generic Template with embedded buttons) and explicitly disable Messenger’s web extensions. This tells the app to skip its built-in browser and launch your system’s default one directly.
Example Code Snippet (Node.js)
Here’s how to structure the API payload to send a button that triggers a system browser open:
const request = require('request'); const sendBrowserLinkButton = (userId, targetUrl, buttonLabel) => { const messagePayload = { recipient: { id: userId }, message: { attachment: { type: "template", payload: { template_type: "button", text: "Tap below to open this link in your default browser:", buttons: [ { type: "web_url", url: targetUrl, title: buttonLabel, messenger_extensions: false, // This line is the key! webview_height_ratio: "full" // Optional, ensures consistent cross-device behavior } ] } } } }; request({ uri: "https://graph.facebook.com/v18.0/me/messages", qs: { access_token: process.env.FB_PAGE_ACCESS_TOKEN }, method: "POST", json: messagePayload }, (err, res, body) => { if (!err) console.log("Browser-link button sent successfully!"); else console.error("Failed to send message:" + err); }); };
Why This Works
- Setting
messenger_extensions: falseoverrides Messenger’s default behavior of using its embedded webview. - This works across mobile and desktop: on phones, it’ll launch your default mobile browser (Chrome, Safari, etc.), and on desktop, it’ll open a new tab in your default desktop browser.
Quick Note on Plain Text Links
If you absolutely have to send a plain text link (not a button), there’s no reliable way to force the system browser—Messenger will almost always open it in its built-in one. Stick to button templates for consistent, desired behavior.
内容的提问来源于stack exchange,提问作者David Alvarez




