Skip to content

Implement countly-sdk-web-LITE for webworker context #103

@whizzzkid

Description

@whizzzkid

Blocks: ipfs/ipfs-companion#1127
Related: Countly/countly-sdk-web#382

The issue:

  • countly-web-sdk ships as an iife which bundles everything, including dependence on window object and implements XMLHttpRequest. Both of these are blockers for implement countly in webworkers (companion background worker and service workers)

Proposed Fix:

  • Since not all APIs are used by ignite-metrics, it's possible to write a minimal set of function calls that can call countly endpoints from within the webworker.
  • APIs Needed:
    • Authentication Flow
    • Session Create Flow
    • Push Event Flow
  • Other considerations:
    • We already implement an eventAccumulator
    • We will need a batching mechanism to not overwhelm the endpoint.
  • Limitations:
    • webworkers don't have access to DOM, window, XMLHttpRequest and localStorage, so:
      • use fetch to open connections to countly endpoints
      • use indexedDB for storage needs. The browser API is awful to use, but projects like Dexie provide a decent API to work with indexedDB.
  • Shipping:
    • Since webpack supports webworker build target as of v5. We can simply provide an export target without changing a lot of things.

Other Thoughts

  • If countly can implement a modular SDK, we might be able to treeshake most of unreachable code and shim window if still needed.
  • In the short term this can help unblock and have light and sane way of communicating with countly.

CC: @SgtPooki

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions