# Feedback on "on-discourse" javascript for setting up custom JS for each page?

**URL:** <https://meta.discourse.org/t/feedback-on-on-discourse-javascript-for-setting-up-custom-js-for-each-page/285647>\
**Category:** Development\
**Created:** [November 16, 2023, 3:48am UTC](https://meta.discourse.org/t/feedback-on-on-discourse-javascript-for-setting-up-custom-js-for-each-page/285647 "2023-11-16T03:48:54Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![Chris\_Dawson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chris_dawson/32/184486_2.png) [@Chris\_Dawson](https://meta.discourse.org/u/Chris_Dawson)\
**Post date:** [November 19, 2023, 1:48pm UTC](https://meta.discourse.org/t/feedback-on-on-discourse-javascript-for-setting-up-custom-js-for-each-page/285647/14 "2023-11-19T13:48:47Z")

</div>

Hi @RGJ I have been trying to figure out how to do this, and have to admit I’m getting confused. It appears the plugin API has changed a bit over the years and I’m not sure how to get what’s current, or see an example.

Your code looks like it goes into an HTML page somewhere as it is wrapped by the script tags. I was using code like this which is the JS file itself.

[https://extrastatic.dev/publicdo/publicdo-discourse-plugin/-/blob/main/assets/javascripts/discourse/initializers/kanji.js?ref\_type=heads](https://extrastatic.dev/publicdo/publicdo-discourse-plugin/-/blob/main/assets/javascripts/discourse/initializers/kanji.js?ref_type=heads)

How do I modify my plugin to use the code you provided? Is this code you suggested something that goes into a plugin, or do I put it into a theme, or otherwise add it to the pages?

I tried to use code like this:

```plaintext
export default {
  name: 'publicdo',
    initialize() {
     withPluginApi('0.1', api => {
                api.onPageChange(() => {
                   console.log('Run my code here.');
                });
      });
    }
}

```

But, this fails with `Uncaught (in promise) ReferenceError: withPluginApi is not defined` so it clearly isn’t something that generally loaded JS receives.

---

_[View the full topic](https://meta.discourse.org/t/feedback-on-on-discourse-javascript-for-setting-up-custom-js-for-each-page/285647)._
