How to register comm target in Jupyter lab?

Following Jupyter notebook example on Opening a comm from the kernel, I was able to initiate communication between the kernel and the notebook.

Every time I invoke fetchData → It initiates a new connection, sends fetchParams and once it’s ready it receives the data and activates a callback.

The code is running from python files and invokes js code as well.

js (this is a js function I can run the notebook with %%js or even the console)

function fetchData(fetchParams, callback) {
    const comm =
    Jupyter.notebook.kernel.comm_manager.new_comm('comm_target', {{}})

    comm.send(fetchParams)

    comm.on_msg(function(msg) {
        const data = JSON.parse(msg.content.data['data']);
        if (callback) {
            callback(data)
        }
    });
}

python (front_listener_get_data is a python function that returns data from the kernel)

get_ipython().kernel.comm_manager.register_target("comm_target", front_listener_get_data)

It’s working fine on Jupyter notebook but when I’m running it on Jupyter lab - I get this error

caught ReferenceError: Jupyter is not defined

I found this solution, but it requires me to use import { Kernel } from "@jupyterlab/services"; and nodejs, which I prefer not to do since it will break the current architecture of the entire project. This is a small feature within a bigger project.

Any suggestions on how I can register this comm without using npm?