-
Notifications
You must be signed in to change notification settings - Fork 44
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
Async createObjectURL #84
Comments
I'm not sure I understand why it would be useful to be able to create a URL that references content that contains that same URL? |
@mkruisselbrink for situations where modules have circular dependencies. This can be used for situations where you are instrumenting a source text with code coverage for example. |
I should clarify, // ./a.mjs
import './b.mjs' // ./b.mjs
import './a.mjs' Has the same problem of being unable to generate the URLs in a circular manner. |
The problem isn't clear enough to me to be able to recommend any particular solution here. |
@annevk I have a working example of the problem in https://github.com/bmeck/browser-hooking/blob/adc8e6767fd6147b662258c765f7923b28105aed/entry.mjs#L3 , I have a Web Worker rewriting ES Modules, which may have circular dependencies. I am not using service worker due to some problems with first load not being able to be integrated against. In particular the worker cannot resolve circular dependencies since the URL generated by |
It seems service workers would be the natural solution here. Creating blob URL strings which are not immediately backed by a |
@annevk 2 points:
When does the Blob content access happen? I don't see it in https://w3c.github.io/FileAPI/#unicodeBlobURL |
See https://url.spec.whatwg.org/#url-parsing. (Given that we might be able to get origin policies before loading something from a domain I suspect that if that's successful we might also pursue loading a service worker before the resource too.) |
@annevk that seems it just needs a flag for pending blob body rather than assuming the existence of a URL implies a body. |
How would that work with synchronous XMLHttpRequest? I don't think it would be as simple a change as you assert. |
|
What I'm saying is that you need to go through all the cases that expect URL's object to carry a |
@annevk do you think races could be avoided with a service worker that does work on initial page load? |
I don't really see similar issues there and it's also not further enshrining this extremely awkward setup where a string keeps an object alive. |
@annevk can't we already make a string keep objects alive in more simple ways? const ns = await import('data:text/javascript,export default {}');
assert(typeof ns.default === 'object'); I don't find the argument compelling when we have another way to do exactly that. |
I don't think I'm familiar enough with modules to see the similarity. |
@annevk Module Map in HTML / ECMA262 is Idempotent. If you |
Lifetime of the realm is less long than blob URLs I'm pretty sure (although that's still not defined in detail unfortunately). |
@annevk correct, blob stores appear to be per tab in browsers rather than per realm. They even cross workers. |
Ah, I should note that I am using the feature of crossing realms on purpose in my example above. |
Closing in favor of #97 |
createObjectURL
is unable to generate circular dependencies for ECMAScript Modules due to URLs requiring their content be given at time of creation. This leads to a problem when trying to recreate this file usingcreateObjectURL
:It seems that there is no way to generate the URL for the import statement since it is returned from
createObjectURL
.I would propose there be an async form or controller for this. I am not tied to any given API but can imagine something like:
The text was updated successfully, but these errors were encountered: