Showing results for 
Search instead for 
Did you mean: 

How to prevent UI5 to open multiple Websocket connections?

0 Kudos


I have that requirement to open only a single Websocket connection per client per application.

I want to use the  implementation in UI5. But I have the issue that everytime the application opens in a new tab/window a new Websocket connection is opened. I can see multiple connections inside T-Code SMICM.

What I've tried:

I found that SharedWorker - Web APIs | MDN ( could be a solution, but I can't manage to run the Websocket code inside the SharedWorker API.



var resourceUrl = sap.ui.require.toUrl("worker.js");
const worker = new SharedWorker(resourceUrl);
//or this
//const worker = new SharedWorker("worker.js");


worker.js (file exists right next to Component.js):


const ws = new`ws${location.protocol === "https:" ? "s" : ""}://${}/sap/bc/apc/sap/z_apc`);

ws.onmessage = ({ data }) => {

onconnect = e => {


Whenever I want to run the SharedWorker constructur, I am getting this error:


Is there maybe another approach to prevent UI5 to open multiple Websocket connections?

Any suggestions would be helpful.


View Entire Topic
0 Kudos

You have to provide the module path to toUrl method.

var resourceUrl = sap.ui.require.toUrl(module_path + "/worker.js");


0 Kudos
Ok, I don't get the error "Failed to fetch worker script" anymore. But nevertheless the SharedWorker doesn't work as intended. The worker script is still not executed.