Api

Nuxt App Hooks

scripts:updated

  • Type: (ctx: { scripts: Record<string, NuxtDevToolsScriptInstance> }) => void | Promise<void>

Triggered after Nuxt updates the script status.

Nuxt uses this internally for the DevTools, but you can use it however you see fit.

plugins/nuxt-scripts.ts
export default defineNuxtPlugin({
  setup() {
    useNuxtApp().hooks.hook('scripts:updated', (ctx) => {
      console.log('Scripts updated', ctx.scripts)
    })
  }
})

script:instance-fn (Unhead Hook)

  • Type: (ctx: { script: ScriptInstance<any>, fn: string | symbol, args: any, exists: boolean }) => HookResult

This is an Unhead head hook (not a Nuxt app hook). It's fired when accessing properties via the proxy instance and is accessed via injectHead().hooks.hook(...).

Nuxt also uses this internally for the DevTools, but you can use it however you see fit.

export default defineNuxtPlugin({
  setup() {
    const head = injectHead()
    head.hooks.hook('script:instance-fn', ({ fn, args }) => {
      console.log('Function called:', fn)
    })
    const { proxy } = useScript()
    proxy.doSomething() // Function called: doSomething
  }
})