vConsole Vue DevTools Plugin
vue-vconsole-devtools is a specialized plugin designed to embed the official Vue.js DevTools directly into vConsole, a lightweight front-end developer tool primarily used for debugging mobile web pages. This enables developers to inspect Vue component states, props, events, and Vuex/Pinia stores directly within a mobile browser's vConsole interface, obviating the need for a desktop browser's Vue DevTools extension. The current stable version is 1.0.9. Releases are infrequent, focusing on compatibility fixes with newer versions of vConsole and Vue DevTools. Its key differentiator is providing a fully integrated Vue debugging experience in environments where traditional browser extensions are unavailable or impractical, such as WebView or mobile Safari/Chrome without remote debugging capabilities. It is framework-agnostic for its vConsole integration but specifically targets Vue.js applications for its debugging capabilities.
Common errors
-
ReferenceError: process is not defined
cause Webpack or other bundlers might not correctly shim or define Node.js globals like `process` for browser environments, which the plugin might have relied on in older versions.fixUpdate to `vue-vconsole-devtools` v1.0.9 or later. If the issue persists, configure your bundler (e.g., Webpack's `ProvidePlugin` or `DefinePlugin`) to define `process.env.NODE_ENV` or provide a `process` shim. -
Uncaught TypeError: Cannot read properties of undefined (reading 'contentWindow')
cause This error typically indicates that the `vue-vconsole-devtools` plugin is trying to access the `contentWindow` property of vConsole's iframe, but the iframe element or its content is not yet available or incorrectly referenced, often due to a vConsole version mismatch.fixEnsure both `vconsole` and `vue-vconsole-devtools` are updated to their latest stable versions (e.g., `vue-vconsole-devtools` >= 1.0.8). Verify that `vConsole` is initialized and ready *before* `initPlugin` is called. -
Vue DevTools tab is not visible or shows 'No Vue app detected.' in vConsole
cause The Vue DevTools global hook was not properly initialized or Vue's devtools flag is off, preventing the plugin from connecting to the Vue instance.fixFor Vue 2.x, add `Vue.config.devtools = true;` and `window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit("init", Vue);` *before* creating your root Vue application instance. For Vue 3, ensure `@vue/devtools` is correctly set up for your build environment to enable detection.
Warnings
- breaking When using Webpack, bundling issues might cause `process` environment variables to be inaccessible, leading to runtime errors. This was particularly prevalent in earlier versions.
- gotcha Older versions of vConsole (specifically 3.14.6) could lead to an issue where `contentWindow` was not found when the plugin attempted to interact with vConsole's iframe, making the DevTools non-functional.
- gotcha Initial versions of the plugin might have had compatibility issues with Safari browsers, preventing the DevTools panel from opening correctly.
- gotcha For Vue 2.x applications, `Vue.config.devtools` must be explicitly set to `true`, and the `window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit('init', Vue)` call is necessary for the plugin to detect and hook into your Vue application. Without this, the 'Vue' tab might not appear or might not show application details.
Install
-
npm install vue-vconsole-devtools -
yarn add vue-vconsole-devtools -
pnpm add vue-vconsole-devtools
Imports
- initPlugin
import VConsoleDevtools from 'vue-vconsole-devtools';
import { initPlugin } from 'vue-vconsole-devtools'; - VConsole
const VConsole = require('vconsole');import VConsole from 'vconsole';
- Vue
const Vue = require('vue');import Vue from 'vue';
Quickstart
import Vue from 'vue';
import VConsole from 'vconsole';
import { initPlugin } from 'vue-vconsole-devtools';
// 1. Initialize vConsole first
const vConsole = new VConsole();
// 2. Initialize the vue-vconsole-devtools plugin
// This must be called before creating your Vue root instance.
initPlugin(vConsole);
// 3. For Vue 2.x, ensure devtools is enabled and emit the global hook
// This makes Vue DevTools aware of your Vue instance.
// This step is crucial for the plugin to detect your Vue application.
Vue.config.devtools = true;
if (window.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit("init", Vue);
}
// 4. Create your Vue application
const app = new Vue({
data() {
return {
message: 'Hello vConsole Vue DevTools!',
counter: 0
};
},
template: `
<div>
<h1>{{ message }}</h1>
<button @click="counter++">Increment: {{ counter }}</button>
<p>Check the vConsole panel for Vue DevTools tab.</p>
</div>
`
});
app.$mount('#app');
// Optional: Append a root element for the Vue app if not already in HTML
if (!document.getElementById('app')) {
const el = document.createElement('div');
el.id = 'app';
document.body.appendChild(el);
}
console.log('vConsole and Vue DevTools plugin initialized. Look for the "Vue" tab in vConsole.');