From 93ea9c20337a652defbd90fe41932a43d252baa3 Mon Sep 17 00:00:00 2001 From: "Acid Chicken (硫酸鶏)" Date: Thu, 9 Mar 2023 14:35:38 +0900 Subject: chore(frontend): add debugger for #6864 (#10270) --- packages/frontend/src/debug.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 packages/frontend/src/debug.ts (limited to 'packages/frontend/src/debug.ts') diff --git a/packages/frontend/src/debug.ts b/packages/frontend/src/debug.ts new file mode 100644 index 0000000000..5715acf674 --- /dev/null +++ b/packages/frontend/src/debug.ts @@ -0,0 +1,27 @@ +import { type ComponentInternalInstance, getCurrentInstance } from 'vue'; + +export function isDebuggerEnabled(id: number): boolean { + try { + return localStorage.getItem(`DEBUG_${id}`) !== null; + } catch { + return false; + } +} + +export function switchDebuggerEnabled(id: number, enabled: boolean): void { + if (enabled) { + localStorage.setItem(`DEBUG_${id}`, ''); + } else { + localStorage.removeItem(`DEBUG_${id}`); + } +} + +export function stackTraceInstances(): ComponentInternalInstance[] { + let instance = getCurrentInstance(); + const stack: ComponentInternalInstance[] = []; + while (instance) { + stack.push(instance); + instance = instance.parent; + } + return stack; +} -- cgit v1.2.3-freya