-
Notifications
You must be signed in to change notification settings - Fork 25
Injection API #189
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
base: develop
Are you sure you want to change the base?
Injection API #189
Conversation
For clarity
In anticipation of readiumCSS variants
| // Validate allowed domains - they should be proper URLs for external resources | ||
| this.allowedDomains = (config.allowedDomains || []).map(domain => { | ||
| try { | ||
| new URL(domain); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the existence of this API: https://caniuse.com/wf-url-canparse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to drop support for Safari < 17? I’ll gladly switch to URL.canParse if we do, but I prefer to double-check yet as it was my initial reason not to use it. 😅
only replying because of this (and bc i'm nosy), please ignore me if you don't want my feedback! very excited for this! seems like a great improvement over manually injecting custom styles and fonts! based off of nothing other than seeing the option to inject scripts, and since it's been a longer-standing goal to mark the I guess I don't have a good alternative if limiting the amount of manual interaction possible with the Navigator is the main goal of deprecating Probably an overly premature commet, knowing very little about the surrounding context! |
Oh trust me this is greatly appreciated as we need this type of feedback and input to get things right, especially as this API is meant to be shared across toolkits 🙏 It will help tremendously for discussing this with other maintainers.
Perhaps not the solution to everything. As you are aware we want to implement the Decorator API properly for instance, but it should be an alternative to cover features we do not have helpers/other APIs for. So it should be flexible enough to allow users to implement what we won’t or haven’t yet.
Interestingly, I have been anticipating more advanced use cases myself. Admittedly, our first iteration is kept simple because we need to start with something and we need support for fonts, and some other simple scripts, but I was trying to imagine cases where the current interface would be problematic. Injecting functions is an interesting idea because blob is very TS-Toolkit specific – we’ve been historically using this for scripts and styles we inject into DX in general, and functions in particular, are something we want to investigate for sure. I can think about it but if you have examples off the top of your head and expectations of how it could preferably work and some time to document them, this will be warmly welcome. |
This PR adds an Injection API so that resources can be passed to the Navigator in order to inject them in a given list of resources – regex is also an option.
For instance:
At the moment, the API accepts either a
Blobor aurl. For CSP, a list ofallowedDomainshas to be passed to check whetherurlis valid and create alink/scriptto it. It does not accept a raw string.An
Injectorclass is taking care of applying rules, etc. Blobs URL are also shared and released when possible, so that they are not duplicated for each document.More testing to do. Although no memory leaks have surfaced during the initial extensive testing, there is additional testing to do with more complex use cases such as significant scripts. I must also migrate the internal scripts and stylesheets we inject by default to the API.
Probably some improvements to make as well, as you need to be very explicit through attributes, etc.
So it’s time to open a draft PR so that issues can be caught early, and inputs/feedbacks collected for API improvements.