Problem Passing Value from JavaScript to JavaScriptToBubble Element

Hi Everyone,

I tried setting up an HTML element with some JS code inside a set of script tags, with the intent to send the result of a function to a JavaScriptToBubble element. However, nothing I do is successfully passing the result to the JavaScriptToBubble element. This is particularly confusing because I have used this process many times before, including on the same page.

I confirmed that the output of the function was getting produced properly by also writing it to the console. I even set up a blank page with a very simple example just to test and still, nothing. Below are my settings, along with the output to the console

I do see the bug in custom HTML ReferenceError warning, but that seems to show up even with my html elements where I am able to pass the results to the JavaScript to bubble element.

I was wondering if anyone has had similar trouble before, and how they fixed it, or if there is anything glaringly obvious in my settings that needs to be changed that I somehow missed. Adding to my confusion, is that this did in fact work for a brief moment, before not working again.

Thanks!

As an additional curveball, I just ran JS code server side and was able to successfully pass the result to the same JS to bubble element, so I do wonder if this has something to do with how the HTML Element is getting rendered?

Hey @ryanellman, the Javascript to Bubble element has to be visible to work.

It could be either hidden on page load or you are running the script before it is rendered.

Good luck!

Thanks!

Yes, I had looked into that and made sure everything was visible on page load but that did not fix it. It is just strange that this is working seamlessly in so many other parts of my app. I certainly wish there was a a native solution for running custom javascript but in the meantime, it seems like I am able to keep things moving by doing this function server side, which is not a problem in this case for my app.

If you can run the function from the console once the page is loaded, it’s likely that the code within the html element is triggering before the JS to bubble exists.

You could play around with a delay, or I think there’s a ‘wait till page rendered’ on the html element itself

1 Like

I have a small suggestion for you, I myself have run into weird issues, especially with timing when using javascript to bubble. I find it’s very hard to manage reliable code using this method.

I recommend taking a bit of time to learn about the bubble plugin editor, it will save you some time in the future! You will run into less bugs such as this one, and it will run without the extra layer of code javascript to bubble uses to interpret your code. In other words, it should technically perform better and you will have an easier time :slight_smile:

Thank you, that does make sense. Something must be incidentally structured in the other parts of my app that are preventing this from being an issue, so I must have lucked out until this point.

Since running it server side is working for now, I will probably continue with that method.

Thank you Jonah, I agree - this is something I have been putting off learning but really need to get around to doing because I admittedly use a lot of custom code in my apps. With all the time I have spent looking for workarounds to figuring out how to build a plugin, I am sure I could have learned the plugin editor many times over at this point! :smile: