I need to use javascript/jquery to click a button on a managed custom aura component when the page loads. Its managed so I can't edit the component code.

I can add the Javascript to the page using "Edit Head Markup" in the Experience Builder.

The Lightning Locker DOM protection is not allowing me to get the element I need to trigger a click.

Is there any way around this?

  • set the api version of your Aura component to v39, then it won't use the Locker Service.
    – ViqMontana
    Commented Dec 7, 2021 at 17:01
  • 1
    This is an X-Y Problem. As you've discovered, what you've tried isn't working. There might be another solution, but you'll need to tell us what it is you're trying to do (not this solution, the Y problem, but the original X problem).
    – sfdcfox
    Commented Dec 7, 2021 at 17:15

1 Answer 1


The solution was to use the x-oasis-script html tag that disables the shadow dom. I added style="display:none" otherwise the code shows when the page is loading.

I had to use a setTimeout to wait for the page to load completely because the components I needed to access were not fully loaded when the dom or window were loaded, but I'm sure is a better wait to wait for an element to load.

<x-oasis-script style="display:none">
window.addEventListener('load', function () {
  setTimeout(() => {  
var clickEvent = new MouseEvent("click", {
    "view": window,
    "bubbles": true,
    "cancelable": false


}, 2000);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .