Wrap a web app you already have in a mini-app and it keeps working, with access to payment, location and the user's profile. This page covers what the pieces are, the SDK that joins them, and the three things that will otherwise cost you an afternoon.
<web-view>. If you are building screens as mini-app pages instead, read Native mini-app — most of the API advice there does not apply to a web app, and vice versa. Not sure? Choosing your path.Three things, nested inside each other. The docs use these three names precisely, so it is worth two minutes now: your web app is what you already have, the shell mini-app is the small native wrapper you add around it, and the host is the Shoppingate app itself.
Installs and launches your mini-app. Draws the title bar and the back control, and owns the things your app wants: the wallet, the camera, the address book, the signed-in user — and the permission prompt in front of each of them.
You write this once and barely touch it again. It holds the full ft.* runtime, so it is the only side that can reach the parts the JSSDK leaves out — the profile, the microphone, Bluetooth, the calendar — and it is where a deep-link query arrives. It renders no screens of its own.
Every screen the customer sees. It ships as it is, with no rewrite, and it updates when you deploy — no new mini-app version, no review. It loads the JSSDK, which gives it an ft of its own: smaller than the shell's, and enough for most of what it needs.
So the shell is plumbing and the web app is the product. The split that follows from that is the only one you have to plan around — your web app makes some calls itself, and asks the shell for the rest:
ft.callNativeAPI('orderPayment', …) goes straight from your web app's JavaScript to the host, and the result comes back in a callback. The shell is not involved and declares nothing. Payment, order history and support tickets all work this way.
Anything that is a runtime API — the user's profile, the microphone, Bluetooth, the calendar — only the shell can call. Your web app sends it a request, the shell makes the call and sends the answer back. You write that relay once; it is the same few lines for everything.
Which calls go which way is Web app and shell calls.
Studio ships a Webview template that gives you the shell. The code below is what the template contains, so you can read it before you generate it — and so you can build the shell by hand if you would rather.
Load it in your web app. One file, no build step, no package to install.
<!-- Load it in the TOP-LEVEL document of your page. --> <script src="https://shoppinggate-public.s3.ap-south-1.amazonaws.com/webview-sdk/sg-jssdk-1.4.20.js"></script>
Download: sg-jssdk-1.4.20.js. Vendor it alongside your app if you would rather not depend on the CDN at runtime — the version is pinned in the filename deliberately, so an upstream change cannot alter what your web app does.
ft.callNativeAPI — the call that reaches host functions — needs 1.4.1 or later.
ft is not the mini-app's ftBoth are called ft, which makes this easy to miss. They are different objects with different surfaces, and most confusion in a wrap traces back to assuming they are the same.
ft.callNativeAPI, ft.getLocation, ft.chooseLocation, ft.chooseImage, ft.request, storage, ft.miniProgram.*, ft.getAppletInfo, ft.complete.ft.* APIs. Your shell can call any of them and relay the answer to your web app.That asymmetry is the main thing to plan around, and web app and shell calls covers it properly — including how the shell relays the rest.
// `ft` exists only inside a web-view. Opened in a desktop browser there is no ft at
// all, so guard once rather than letting every call throw.
var inWebView = typeof ft !== "undefined";
if (inWebView) {
ft.miniProgram.getEnv(function (res) {
console.log("inside a mini-app:", res.miniprogram);
});
// Tells the host the page finished loading. REQUIRED if the mini-app sets a web-view
// load timeout: without it the page is treated as having failed, however well it
// rendered.
if (typeof ft.complete === "function") ft.complete();
}ft.complete() is easy to skip and expensive to skip. If the mini-app sets a web-view load timeout, a web app that never calls it is treated as having failed no matter how well it rendered.
The SDK binds its bridge to the top-level document. A document inside an iframe still loads the script and still defines ft, so every method is present and nothing throws — calls just never come back.
// The one failure that looks like success.
//
// A page inside an iframe still loads the SDK and still defines `ft`, so every method is
// present and nothing errors — but the bridge binds to the TOP-LEVEL document, so calls
// simply never come back. You get timeouts, not errors, which sends you looking at the
// host instead of at the frame.
if (window.top !== window.self) {
console.error("Not the top-level document — the bridge will not bind.");
}Your web app's domain must be in the allow list in the developer portal. Until it is, the web-view loads nothing and binderror is the only signal — there is no message on screen.
ft.downloadFile has its own allow list, separate from the web-view one. So your web app can load perfectly and a download still fail, which looks like a broken API rather than a missing registration.
localhost works in the simulator only, and needs URL checking switched off. A device cannot reach your laptop and localhost can never be allow-listed.
Three pages get a wrap working. The rest you read when your app needs what they cover.