Skip to content

Instantly share code, notes, and snippets.

@bisubus
bisubus / global-detection.js
Created June 7, 2020 10:02
Cross-platform global variable detection with fallbacks
// self is window proxy in IE<=10, eval handles this
var _global = (function () { try { return Function('return this')() } catch (e) {} })() // browsers without CSP, Node
|| typeof globalThis !== 'undefined' && globalThis // new and polyfilled browsers/workers CSP, newer Node with broken eval
|| typeof self !== 'undefined' && self // old browsers/workers with CSP
|| typeof global !== 'undefined' && global // old Node with broken eval
|| typeof window !== 'undefined' && window; // fallback for exotic environments
@bisubus
bisubus / main.js
Created August 4, 2021 09:44
Custom implementation of the missing onAbort hooks in vue-router
import Vue from 'vue';
import VueRouter from 'vue-router';
import applyOnRouterAbortShim from './on-router-abort-shim';
Vue.use(VueRouter);
const router = new VueRouter(...);
applyOnRouterAbortShim(router);