From 5991858ebe91909cc3d94181e658bd3a2019dc7a Mon Sep 17 00:00:00 2001 From: Chris Peyer Date: Thu, 14 Sep 2023 04:05:48 -0700 Subject: [PATCH] Update lana.md with outside usage instructions --- libs/utils/lana.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/libs/utils/lana.md b/libs/utils/lana.md index 3aebd48e97..c0e0754a2d 100644 --- a/libs/utils/lana.md +++ b/libs/utils/lana.md @@ -73,6 +73,37 @@ try { } ``` +## Useage outside of Milo + +If you can use dynamic imports you can do similar to milo: +``` +function loadLana(options = {}) { + if (window.lana) return; + + const lanaError = (e) => { + window.lana?.log(e.reason || e.error || e.message, { errorType: 'i' }); + }; + + window.lana = { + log: async (...args) => { + window.removeEventListener('error', lanaError); + window.removeEventListener('unhandledrejection', lanaError); + await import('https://milo.adobe.com/libs/utils/lana.js'); + return window.lana.log(...args); + }, + debug: false, + options, + }; + + window.addEventListener('error', lanaError); + window.addEventListener('unhandledrejection', lanaError); +} +``` +This has the advantage of not loading lana until it's needed. This also will automatically catch any global errors or unhandledrejections. + +If you need to include lana.js directly (or can't load dynamic modules) you can use a script tag: +`` + ## Notes * Implicit Error logging * There are 2 global event listeners added by LANA to catch errors: