Vue Browser Update Wrapper
`vue-browserupdate` is a Vue.js wrapper for the popular `browser-update.org` JavaScript library, designed to streamline the integration of browser version checking and update prompting into Vue applications. It provides a straightforward API to initialize the underlying `browser-update` script and exposes its core events—`onshow`, `onclick`, and `onclose`—as Vue-compatible functions. The current stable version, 1.2.0, indicates a mature wrapper for Vue 2 applications. Its release cadence typically follows updates to the core `browser-update` library or significant changes within the Vue.js ecosystem. The package's primary differentiator is its simplicity in encapsulating the browser update notification logic within a standard Vue plugin pattern, minimizing boilerplate for developers.
Common errors
-
TypeError: Vue.use is not a function
cause Attempting to call `.use()` on an undefined or incorrect Vue object, or Vue is not globally available/imported correctly.fixEnsure `import Vue from 'vue';` is present and that `Vue.use(VueBrowserUpdate)` is called after Vue itself is properly loaded and initialized. -
TypeError: Cannot read properties of undefined (reading 'onshow')
cause The `Vue.browserUpdate` object, which contains the event handler methods, is accessed before the `vue-browserupdate` plugin has been installed via `Vue.use()`.fixVerify that `Vue.use(VueBrowserUpdate)` is called before any attempts to access `Vue.browserUpdate.onshow`, `onclick`, or `onclose`.
Warnings
- gotcha The `test: true` option forces the browser update prompt to appear regardless of the browser version, which is useful for development and testing but should be removed or set to `false` for production deployments.
- gotcha All configuration for the underlying `browser-update` library must be passed within the `options` key of the plugin's configuration object, e.g., `Vue.use(VueBrowserUpdate, { options: { /* ... */ } })`.
- gotcha This wrapper is primarily designed for Vue 2 applications using the global Vue instance. Its direct usage patterns (`Vue.use`, `Vue.browserUpdate`) are not directly compatible with Vue 3's `createApp` instance-based plugin registration without additional shims or refactoring.
Install
-
npm install vue-browserupdate -
yarn add vue-browserupdate -
pnpm add vue-browserupdate
Imports
- VueBrowserUpdate
const VueBrowserUpdate = require('vue-browserupdate');import VueBrowserUpdate from 'vue-browserupdate';
- Vue.browserUpdate.onshow
import { onshow } from 'vue-browserupdate';Vue.browserUpdate.onshow(() => { /* ... */ });
Quickstart
import Vue from 'vue';
import VueBrowserUpdate from 'vue-browserupdate';
// Install the plugin with custom options
Vue.use(VueBrowserUpdate, {
options: {
container: document.body,
required: { e: -2, f: -2, o: -2, s: -2, c: -2 }, // Example: Require latest 2 versions
text: 'Your browser is outdated. Please update to improve your experience and security.',
// Full options: http://browser-update.org/customize.html
},
test: true, // Enable test mode to always show the prompt
});
// Attach event listeners (optional)
Vue.browserUpdate.onshow(() => {
console.log('The browser update modal is visible.');
});
Vue.browserUpdate.onclick(() => {
console.log('The update link was clicked.');
});
Vue.browserUpdate.onclose(() => {
console.log('The update modal was closed.');
});
// Basic Vue app setup
new Vue({
el: '#app',
template: '<div><h1>My App</h1><p>Browser update prompt will show if conditions met.</p></div>'
});