nuxtseo-layer-devtools 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,34 +24,34 @@ export interface DevtoolsConnectionOptions {
24
24
  * - **Standalone**: running directly in a browser tab with a manual dev server URL
25
25
  */
26
26
  export function useDevtoolsConnection(options: DevtoolsConnectionOptions = {}): void {
27
- const inIframe = window.parent !== window
28
-
29
27
  // Embedded mode: connect via devtools-kit iframe client
30
- if (inIframe) {
31
- onDevtoolsClientConnected(async (client) => {
32
- isConnected.value = true
33
- // @ts-expect-error untyped
34
- appFetch.value = client.host.app.$fetch
35
- watchEffect(() => {
36
- colorMode.value = client.host.app.colorMode?.value ?? (
37
- window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
38
- )
39
- })
40
- devtools.value = client.devtools
41
- options.onConnected?.(client)
28
+ onDevtoolsClientConnected(async (client) => {
29
+ isConnected.value = true
30
+ // @ts-expect-error untyped
31
+ appFetch.value = client.host?.app?.$fetch
32
+ watchEffect(() => {
33
+ colorMode.value = client.host?.app?.colorMode?.value ?? (
34
+ window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
35
+ )
36
+ })
37
+ devtools.value = client.devtools
38
+ options.onConnected?.(client)
42
39
 
43
- if (options.onRouteChange) {
44
- const $route = client.host.nuxt.vueApp.config.globalProperties?.$route
40
+ if (options.onRouteChange) {
41
+ const $route = client.host?.nuxt?.vueApp?.config?.globalProperties?.$route
42
+ if ($route)
45
43
  options.onRouteChange($route)
46
- const removeAfterEach = client.host.nuxt.$router.afterEach((route: any) => {
44
+ const $router = client.host?.nuxt?.$router
45
+ if ($router) {
46
+ const removeAfterEach = $router.afterEach((route: any) => {
47
47
  options.onRouteChange!(route)
48
48
  })
49
49
  // Clean up when devtools client disconnects
50
50
  // @ts-expect-error app:unmount exists at runtime but is not in RuntimeNuxtHooks
51
51
  client.host.nuxt.hook('app:unmount', removeAfterEach)
52
52
  }
53
- })
54
- }
53
+ }
54
+ })
55
55
 
56
56
  // Standalone mode: create appFetch from manually entered URL
57
57
  watch(() => standaloneUrl.value, (url) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxtseo-layer-devtools",
3
3
  "type": "module",
4
- "version": "0.3.5",
4
+ "version": "0.3.7",
5
5
  "description": "Shared Nuxt layer for Nuxt SEO devtools clients.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -1,8 +1,15 @@
1
1
  export default defineNuxtPlugin(() => {
2
+ const inIframe = window.parent !== window
3
+
4
+ // When served from the dev server directly (not in iframe), auto-connect to same origin
5
+ if (!inIframe && !standaloneUrl.value) {
6
+ standaloneUrl.value = window.location.origin
7
+ }
8
+
2
9
  useDevtoolsConnection({
3
10
  onConnected(client) {
4
- const props = client.host.nuxt.vueApp.config.globalProperties
5
- base.value = props?.$router?.options?.history?.base || client.host.app.baseURL || '/'
11
+ const props = client.host?.nuxt?.vueApp?.config?.globalProperties
12
+ base.value = props?.$router?.options?.history?.base || client.host?.app?.baseURL || '/'
6
13
  const $route = props?.$route
7
14
  if ($route) {
8
15
  path.value = $route.path || '/'