Amazon Connect agents work inside the Contact Control Panel (CCP), a web page that runs in a desktop browser. Step away from the desk and the call rings to nobody.
I wanted the official CCP of a company's own Connect instance running on an Android phone, ringing like a normal call even with the screen off or locked. No rebuilt UI, no unofficial API: the same panel the agent already knows.
That turned out to be two problems: one in JavaScript, one in Android.
Problem 1: Android WebView has no SharedWorker
Load the CCP in a WebView and it never finishes starting. The reason is simple: the CCP (through Amazon Connect Streams) opens a SharedWorker, and Android WebView does not implement SharedWorker. window.SharedWorker is just undefined.
The good news: inside the app there is only one page using that worker. A SharedWorker with a single client behaves like a dedicated Worker plus a MessagePort. So I built exactly that.
The page side: a SharedWorker made of a Worker + MessageChannel
(function () {
'use strict';
if (typeof window.SharedWorker !== 'undefined') return; // real one exists: do nothing
if (typeof window.Worker === 'undefined' || typeof window.MessageChannel === 'undefined') return;
// Same URL + same name = the SAME worker, like a real SharedWorker.
// The CCP opens the same worker script more than once on the page.
var opened = {};
function AppSharedWorker(url, options) {
var address = new URL(url, location.href);
address.searchParams.set('__app', '1'); // marker the app intercepts (see below)
var name = typeof options === 'string' ? options : (options && options.name) || '';
var key = address.href + '|' + name;
var worker = opened[key] || (opened[key] = new Worker(address.href, { name: name }));
var channel = new MessageChannel();
worker.postMessage({ __app: 'connect' }, [channel.port2]);
this.port = channel.port1; // a real MessagePort, as the API promises
this._worker = worker;
}
window.SharedWorker = AppSharedWorker;
})();
The page gets worker.port, a genuine MessagePort. The CCP code never knows the difference.
The worker side: making a dedicated worker look shared
The worker script from AWS checks whether it is running as a shared worker by testing if onconnect exists. In a dedicated worker it does not. So a small adapter runs in front of the original script:
// Declare onconnect so the original script believes it is a SharedWorker.
if (typeof self.onconnect === 'undefined') self.onconnect = null;
self.addEventListener('message', function (e) {
var d = e.data;
if (!d || d.__app !== 'connect') return;
e.stopImmediatePropagation();
var ev = new MessageEvent('connect', { data: '', ports: [e.ports[0]] });
if (typeof self.onconnect === 'function') self.onconnect(ev);
self.dispatchEvent(ev);
});
The original script receives a connect event carrying the port, exactly as it would in Chrome.
Gluing it in without touching AWS code
Two WebView features do the wiring:
-
WebViewCompat.addDocumentStartJavaScript(AndroidX WebKit) injects the shim at document start, only for the instance's origin, before any CCP code runs. -
shouldInterceptRequestcatches the worker request marked with__app=1, fetches the original AWS script and serves adapter + original as one response. The worker keeps its real URL, so its relative imports still resolve normally.
AWS code is never copied or modified: it is fetched live and only wrapped.
Problem 2: ringing with the screen off
Getting the CCP to run is half the job. The first real-device test failed in a sneaky way: with the screen on, calls rang perfectly. With the screen off, the call was offered and lost without a sound.
The hidden trap: the WebView stops your JavaScript
I measured it on the emulator. When the screen turns off, the window goes away and the WebView tells its engine the page is hidden. About a minute later, all of the panel's code stops: page and worker, including the heartbeat with AWS. Connect offers the contact to an agent whose panel is, in practice, frozen.
The fix is tiny. The panel's WebView always reports itself as visible to the engine:
fun createWebView(ctx: Context): WebView =
object : WebView(ctx) {
// Screen off => window hidden => engine pauses the page after ~1 min.
// For the engine, the panel window is always visible.
// Battery is handled by the call service, not by pausing the page.
override fun onWindowVisibilityChanged(visibility: Int) {
super.onWindowVisibilityChanged(View.VISIBLE)
}
}
This only works responsibly because of what comes next: the app is in a foreground call service while the agent is available, so Android knows it is doing real work. The rest of the Android side is a few pieces working together.
1. Listen to the CCP, not to the screen. A small bridge script subscribes to Streams events and notifies the native side:
connect.contact(function (c) {
c.onIncoming(function () { native('incoming', info(c)); });
c.onConnecting(function () { native('incoming', info(c)); });
});
2. A foreground service of type phoneCall|microphone. While the agent is available, the app runs a foreground service declared with android:foregroundServiceType="phoneCall|microphone" (plus the matching FOREGROUND_SERVICE_PHONE_CALL and FOREGROUND_SERVICE_MICROPHONE permissions). That is what keeps the process, and therefore the WebView and its JavaScript, alive.
3. A partial wake lock during the call. PowerManager.PARTIAL_WAKE_LOCK keeps the CPU running while a contact is in progress, and is released when it ends.
4. A real incoming-call notification. Notification.CallStyle.forIncomingCall(...) with answer and decline actions, plus setFullScreenIntent(...), so the call takes over the lock screen like a carrier call (USE_FULL_SCREEN_INTENT).
5. Audio permissions bridged to the page. WebChromeClient.onPermissionRequest grants the microphone to the CCP's origin only after the Android runtime permission is granted.
What I learned
-
Check feature support before debugging the app. Hours can go into "why doesn't the CCP load" when the answer is one
typeofaway. -
A
SharedWorkerwith one client is just aWorkerwith a port. Emulating the API at the boundary beat patching vendor code. - Wrap, don't fork. Serving adapter + original keeps the app in sync with AWS updates to the CCP for free.
- Test with the screen off, for minutes, not seconds. The WebView pausing a "hidden" page is invisible in a quick test and fatal in real use.
- On Android, "keep JS alive" is a native problem. Visibility reported to the engine, the right foreground service type, a wake lock scoped to the call and the CallStyle notification matter more than anything in the page.
The result
This became Ary CCP for Amazon Connect, an Android app that opens a company's own Amazon Connect panel on the phone: voice calls, chats and WhatsApp conversations that arrive through Connect, ringing even with the screen off.
It is an independent product, not affiliated with AWS or Amazon. If you run an Amazon Connect contact center and your agents are not always at a desk, take a look: aryccp.com.
Questions about the WebView approach are welcome in the comments.
Top comments (0)