ts-odd
ts-odd copied to clipboard
Enhance setup.debug to always expose wn object if true
Problem: some developers using webnative ( like me ) will use tooling like sveltekit and initialize our code in a component, effectively hiding it from the DOM and any kind of tooling we or others might want to build. It's currently impossible to access the wn instance from the devtools console, for example, unless you set a breakpoint in the scope where that variable is created.
From a chat w/Brian:
Hey! Question for you. I have some code in my test sveltekit / wn app now to make it easier for me to create a content script:
onMount(() => {
const DEBUG = true;
if (DEBUG && DEBUG === true) {
navigator.__wn = wn;
}
});
...so I can write code in my content script like:
if (navigator.__wn) {
// this page is definitely using webnative
navigator.__wn.authenticatedUsername().then(console.log)
}
In the codebase we currently have a debug option in setup.ts:
https://github.com/fission-codes/webnative/blob/main/src/setup.ts#L12-L20
When this debug option is set, we could optionally do something like what I have in code example 1 - exposing the wn instance to the top level DOM for convenience.