Button that opens Shopify chat app is refreshing page and then opening

Topic summary

A user encountered an issue where clicking a link to open Shopify’s Inbox chat app (/?chat) was causing an unwanted page refresh before the chat window appeared. The goal was to trigger the chat popup directly, similar to clicking the native chat bubble.

Solution provided:
Another community member suggested using JavaScript to programmatically trigger the chat button click instead of relying on the URL parameter. The solution involved:

  • Adding onclick="openChatBox(event)" to the chat link
  • Implementing a JavaScript function that targets the Shopify Inbox shadow DOM element and simulates a click on the internal chat toggle button

Implementation:
The user initially struggled with where to add the code. After declining a collaborator access offer due to privacy concerns, they received a complete JavaScript snippet that:

  • Listens for clicks on links with href="/?chat"
  • Prevents default navigation behavior
  • Accesses the inbox-online-store-chat element’s shadow root
  • Triggers the chat toggle button programmatically

Outcome:
The solution was successfully implemented by adding the JavaScript code to main.js, eliminating the page refresh issue.

Summarized with AI on October 28. AI used: claude-sonnet-4-5-20250929.

Hello everyone,

I’ve tried searching for a solution only but I can’t seen to find one. I want to have an a link that pops up the chat when clicked, I’m currently using /?chat but this actually refreshes the page and opens the chat, not the desired affect.

How can I pop it up without refreshing the page?

Thanks!

Chris

Hi @cardboardhouse

Can you detail with a screenshot? I will support you figure out if you can detail that

Hi @cardboardhouse

Are you using this app https://apps.shopify.com/inbox ?

It’s hard with a screenshot, but the steps are;

  1. link clicked

  1. Page refreshes, jumps to top of the page and chat pops up

Desired outcome;

  1. Link clicked
  2. Chat pops as, as you would if you clicked the chat bubble directly

yes!

Let try to find Live Chat button on your footer then change the href=“#” & add onclick=“openChatBox(event)”

Then try to add javascript openChatBox(event) function:


Hey, thanks for the reply!

Sorry but I’m not sure what to do;

  1. Where am I adding onclick=“openChatBox(event)”? It won’t let me add it to the link field on the right hand side

  1. Am I adding the script to my base.css?
  1. Let try to edit code

  2. let find the file header.liquid on your code then add it. Don’t use base.css because it only working for CSS code only

If you can’t do it. Let add me as collaborator to support you change it

Hi @cardboardhouse

Does it works?

I couldn’t figure out how to where to add onclick=“openChatBox(event)” :disappointed_face:

Let add me as collaborator then I will try to update code for you. My email: huykon225@gmail.com

Thanks for the offer but I’m not really comfortable adding people I don’t know as collaborator

oh okay. it will difficult to me to support you complete it

No worries, I will definitely let you know if I can’t figure it out and we will have to try this!

let try to add JS code. It maybe works:

document.addEventListener('DOMContentLoaded', function() {
  const chatLink = document.querySelector('a[href="/?chat"]');

  if (chatLink) {
    chatLink.addEventListener('click', function(event) {
      event.preventDefault();
      try {
        const shopifyChatHost = document.querySelector('inbox-online-store-chat');
        if (shopifyChatHost && shopifyChatHost.shadowRoot) {
          const chatToggleButton = shopifyChatHost.shadowRoot.querySelector('button.chat-toggle');
          if (chatToggleButton) {
            chatToggleButton.click();
          } else {
            console.error('Shopify Inbox: Internal chat toggle button not found.');
          }
        } else {
          console.error('Shopify Inbox: Chat host element not found or shadowRoot not accessible.');
        }
      } catch (error) {
        console.error('Error programmatically opening Shopify Inbox:', error);
      }
    });
  }
});

No :disappointed_face:

No it works!! I added it to main.js and works, thanks so much!

that sounds great