Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance setup.debug to always expose wn object if true #405

Closed
jeffgca opened this issue Aug 10, 2022 · 6 comments · Fixed by #476
Closed

Enhance setup.debug to always expose wn object if true #405

jeffgca opened this issue Aug 10, 2022 · 6 comments · Fixed by #476
Assignees
Labels
🧭 critical path enhancement New feature or request

Comments

@jeffgca
Copy link
Contributor

jeffgca commented Aug 10, 2022

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.

@bgins bgins added the enhancement New feature or request label Aug 10, 2022
@jeffgca
Copy link
Contributor Author

jeffgca commented Dec 7, 2022

Bumping this issue because not having this makes it very hard for us to internally debug apps based on WAT and file good bugs.

@icidasset
Copy link
Contributor

@therealjeffg What's stopping people from doing this themselves? Can't you access the navigator or window object in a Svelte component?

I'm worried that if people leave on the debug flag it exposes this object unintentionally.

@bgins
Copy link
Member

bgins commented Jan 24, 2023

For the purposes of accessing Webnative from a devtools extension, I think we can expose less. The basic idea is that the extension will signal to Webnative that it would like debugging information, and Webnative will send window post messages in response. Still determining some of the details, but we'll be tracking it in #460 and oddsdk/odd-devtools#8.

@jeffgca
Copy link
Contributor Author

jeffgca commented Jan 24, 2023

@therealjeffg What's stopping people from doing this themselves? Can't you access the navigator or window object in a Svelte component?

Nothing as far as I can tell, and yes these objects can be accessed from svelte. The intention behind this work is to automagically provide a better developer experience, but only when the debug flag is set to true.

The problem we're trying to address is that currently webnative is a bit of a black box when used within a framework like elm or svelte and it is very difficult to get any info about a currently running app from eg the devtools console, which is by far the most common tool developers use.

I'm worried that if people leave on the debug flag it exposes this object unintentionally.

Can you say more about this? Outside of a framework it is quite likely that the webnative object would be available in the page's global scope. Is this in and of itself a security risk?

We can always mitigate this unintentional risk for behaviours in our examples by eg printing warnings to the console or placing visual warnings in the UI of WAT.

@icidasset
Copy link
Contributor

icidasset commented Jan 30, 2023

I thought a bit more about this and I think it should be fine security-wise exposing the Programs.
I think I'll implement something like this:

globalThis.__webnative.programs["namespace"] = program

and will be configurable.

@icidasset
Copy link
Contributor

@therealjeffg Added to Webnative v0.36, see guide: https://guide.fission.codes/developers/webnative/additional-info#program

@bgins bgins assigned icidasset and unassigned bgins Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧭 critical path enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants