Skip to content

Web version with Refresh Worker does not work when loaded from different origin (e.g. CDN) #24

@angelo-v

Description

@angelo-v

The new refresh worker does not work if the lib is used via CDN, since the worker has to be registered on the same origin. (see also this comment)

Minimal HTML to reproduce the issue:

<script type="module">
        import {Session} from "https://unpkg.com/@uvdsl/solid-oidc-client-browser@0.2.0/dist/esm/web/index.min.js"
        new Session()
</script>

When served and opened in a browser this logs something like:

Uncaught SecurityError: Failed to construct 'SharedWorker': Script at 'https://unpkg.com/@uvdsl/solid-oidc-client-browser@0.2.0/dist/esm/web/RefreshWorker.js' cannot be accessed from origin 'http://localhost:63342'.
    at new Me (Session.ts:36:23)
    at index.html?_ijt=9864dcv3jn9ceshd0aa7oktlqi&_ij_reload=RELOAD_ON_SAVE:6:7

Possible solution

  1. Provide a RefreshWorker.js on the same origin as the app, that loads the actual worker from CDN:
// RefreshWorker.js
import "https://unpkg.com/@uvdsl/solid-oidc-client-browser@0.2.1/dist/esm/web/RefreshWorker.js"
  1. Then intantiate the SharedWorker in the app and pass it to the Session
const refreshWorker = new SharedWorker('./RefreshWorker.js', { type: 'module' });
new Session(refreshWorker)

For this to work the library needs to make it possible to pass the worker in the constructor as an alternative to instantiate it internally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions