redhat-developer / vscode-redhat-telemetry

22 stars 26 forks source link

Support pure web environment #21

Closed apupier closed 1 year ago

apupier commented 1 year ago

vscode-redhat-telemetry package uses several of nodejs-specific globals (such as process and os) that can't be fully polyfilled on a Web environment.

Ideally the vscode-redhat-telemetry package should support a Web environment with checks such as process.web === true and then go from there, avoiding loading node.js specifics on a web env.

/cc @thiagoelg

apupier commented 1 year ago

as a follow-up, it might be interesting to collect specific data of web environment such as browser type and version?

thiagoelg commented 1 year ago

vscode-redhat-telemetry relies heavily on node.js features, and, at the same time, VSCode extensions provide a completely different environment (even on a browser), making adapting this package really difficult.

The only solution I can see is abandoning analytics-node or any other Segment package and implementing this integration manually, using all vscode apis (fs, env, etc).

This is as far as I could go by only adapting vscode-redhat-telemetry, but @segment/analytics-next still breaks because window is not defined (even on a browser 😮) https://github.com/redhat-developer/vscode-redhat-telemetry/compare/main...thiagoelg:support-web?expand=1

fbricon commented 1 year ago

In a web environment, VS Code extensions work in a webworker, so they have no access to the DOM. I need to take a hard deep look at the problem, as it's not trivial (and I suck at TS/JS in general), but in the meantime, you can disable telemetry in a web context like vscode-yaml does: https://github.com/redhat-developer/vscode-yaml/blob/main/src/webworker/yamlClientMain.ts#L33

fbricon commented 1 year ago

See https://github.com/redhat-developer/vscode-yaml/pull/903 for an example of enabling telemetry in a web browser