ShoppingateShoppingateDevelopers
shoppinggate.app ↗
Documentation
  • What is a Mini App
  • Why Mini Apps
  • API integration
  • SDK
  • Webview
  • Mini App architecture
  • Getting started
  • Choosing your path
  • Introduction
    • Introduction
    • Sign up & login
    • Dashboard & analytics
    • Mini-Programs
    • Submit & publish a version
    • App Binding
    • Privacy Settings
    • Allowed URL
    • Users & roles
    • Introduction
    • Become a Mini-App vendor
    • API keys
    • My Mini-Apps
    • Orders
    • Webhook
    • Deep-link config
    • Introduction
    • Install & log in
    • Create a project
    • The workspace
    • Preview & upload
  • Introduction
  • Configuration
  • Lifecycle
  • Routing & query
  • Host functions
  • orderPayment
  • Permissions
  • User info
  • Introduction
  • Configuration
  • SDK
  • Lifecycle
  • Routing & query
  • Host functions
  • orderPayment
  • Permissions
  • User info
  • Web app and shell calls
  • Look and feel
  • Overview
    • Verify user
    • Create order
    • Get order
    • Update order status
    • Charge an order
    • Send a notification
  • Subscriptions
    • Create a subscription
    • List subscriptions
    • Get a subscription
    • Update a subscription
    • Reschedule next charge
    • Change plan (upgrade)
    • Cancel a subscription
  • Webhooks
Web view

Overview & SDK

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.

This section is about a web app inside a <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.

Web app, shell mini-app, host

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.

Host — the Shoppingate app

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.

Your shell mini-app — native, six files

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.

<web-view> — one tag, filling the screen
Your web app — your own server, over HTTPS

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:

web app → host

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.

web app ⇄ shell

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.

The SDK

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.

Your web app's ft is not the mini-app's ft

Both 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.

Where
What ft gives you
In your web app
From the JSSDK. A smaller set: ft.callNativeAPI, ft.getLocation, ft.chooseLocation, ft.chooseImage, ft.request, storage, ft.miniProgram.*, ft.getAppletInfo, ft.complete.
In a native page
The full mini-app runtime — around 45 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.

Knowing you are inside a web view

// `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.

It must be the top-level document

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.");
}
You get timeouts, not errors. That sends you looking at the host, the network, your handlers — anywhere except the frame. If calls hang and nothing logs, check this first. It rules out anything that serves your web app inside an app shell or a preview wrapper.

Register the host

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.

The rest of this section, in order

Three pages get a wrap working. The rest you read when your app needs what they cover.

Read these first
What it gives you
The shell mini-app
The handful of files that host your web app, and the four values you change to point the shell at your own app.
Web app and shell calls
Which APIs your web app calls itself, which ones the shell mini-app has to call for it, and the relay that carries a request and its answer between the two.
Host functions
Payment, order history and support tickets — what each one takes, what it returns, and how to call it straight from your web app's JavaScript.
Then, as you need them
What it gives you
Permissions
If you use the camera, album, location, microphone, contacts or calendar. Two separate layers can each deny the call, and telling them apart is the whole job.
Deep links
If a notification, a share or the super app's orders list should land the customer on an exact screen rather than your home screen.
Look and feel
Before you submit. The work in your own CSS and JavaScript — bounce, zoom, safe areas, both themes, Arabic — that stops a wrapped web app feeling like a website.