Closed frederikb closed 7 months ago
That's an interesting case. I hadn't considered service workers. I'll work on it. I expect that verifying that it works will be harder than the fix itself.
I could probably stub out the global document, but with what kind of location?
That would work. If you stub out the location to just an empty string, it should work fine. Ultimately, the feature that code supports doesn't make sense in the context of service workers, so whatever you need to do to make it not blow up shouldn't hurt anything else you're trying to use the library for.
I published a fix that I think should work. Let me know if you have you problems.
Thanks @jdesrosiers for the fast turnaround! I can happily confirm that I can validate files using a schema embedded in my codebase.
Enjoying your libary so far, thanks a lot!
Glad it's working out for you!
Hi,
I would like to use your library in the context of a browser extension for Chrome/Firefox built using the Web Extensions API.
The main logic of the extension is run in a so-called background script. In Manifest V3 versions of that API these are executed using service workers. The main impact is of course that we do not have a reference to the DOM and the
document
global variable is undefined.When running the following code in this context I unfortunately get an exception because it assumes a normal web browser context:
The error:
The stacktrace is a bit mangled due to not having source maps set up, but the gist of it is that it's failing in @hyperjump/browser:
while attempting to determine
baseUri
because it assumes a browser context.My schema does not have any references to external schemas, neither absolute nor relative to.
Thanks!