My VF page is directly embedded into the utility bar. As I have a WebSocket used to stream some events, I would like to find a way to use LMS to stream those events to LWC and Aura components. On my LWC component side I'm using the application scope right now.

I found that LMS works in both directions when handling click events.

I can't figure out the approach to stream LMS messages, mainly from VF to LWC. As far as I understand it needs some user interaction. Is that a restriction? Is there a way to skip user interaction when we need to stream in different LMS message channels. I have done a simple hacky solution, but the approach is just terrible, IMO.

Is there any better approach that is part of the best practices? Or at least how could I turn it into a mixin or is it possible to be converted to pubsub?

Are the any events that could be triggered and listened to so that sending the LMS message could work?

Hacks that I've tried so far include:

var event = new Event('click',{bubbles:true,composed:true});
var event = new PointerEvent('click',{bubbles:true,composed:true});

But the problem with both them that only the onClick function is executed. When it tries to send the LMS message it is not received on the subscriber function.

Terrible Hacky Solution:

This solution transfers counter from VF page to LWC component (WIP).


    <?xml version="1.0" encoding="UTF-8"?>
<LightningMessageChannel xmlns="http://soap.sforce.com/2006/04/metadata">
    <description>Message Channel to update connectivity state</description>


<apex:page controller="TestController">
        <apex:outputPanel id="counter">
            <!-- <apex:outputText value="Watch this counter: {!count}"/> -->
            <input type="hidden" value="{!count}" placeholder="hidden" name="hidden" class="test"/>
                var testE = document.querySelector('input.test');
                var c = {
                    call: sforce.one.publish,
                function lms(newValue, oldValue) {
                    c.call(c.test, {test: 'changed from ' + oldValue + ' to ' + newValue + '!'});
                if (document.readyState === 'complete') {

        <apex:actionPoller action="{!incrementCounter}" reRender="counter" interval="5"/>



<?xml version="1.0" encoding="UTF-8"?>
<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">


    <lightning-card title={title} icon-name="custom:custom19">
        <div slot="actions">
            <span class="lightning">LWC</span>
        <p>Message from VF: {test}</p>


import { LightningElement, track,wire } from 'lwc';
import Test from "@salesforce/messageChannel/Test__c";
import {
    // unsubscribe,
} from 'lightning/messageService';
export default class LwcTest extends LightningElement {
    subscription = null;
    connectedCallback() {
    subscribeToChannel() {
        if (!this.subscription) {
            this.subscription = subscribe(this.subscribeContext,
                Test, (message) => {
                }, { scope: APPLICATION_SCOPE }

    handleTest(message) {
        const {
            test: t,
        } = message;
        this.test = t;



<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
        <targetConfig targets="lightning__UtilityBar">
          <property name="title" type="String"/>
  • Haven't tried your specific scenario, but sometimes you can execute the click function (developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click) on some HTMLElement instance in JavaScript in lieu of an actual user interaction. Have you tried that yet? Jan 30 at 14:10
  • well, I have tried: var event = new Event('click',{bubbles:true,composed:true}); element.dispatchEvent(event); and replacing it with PointerEvent as well. The clicks work on themself, but the LMS message is not transmitted Jan 30 at 14:26
  • What about simply element.click()? Jan 30 at 18:04
  • I will check that tomorrow, but I guess it is more complicated. I've updated my question so that includes one simple approach using some DOM magic. Jan 30 at 20:35


You must log in to answer this question.