make the base of URL constructor configurable?
I have a rather niche use case (and will probably deploy a fork for now) where I'm trying to use HTMX out of an iframe with [href=about:srcdoc]. So when HTMX tries to construct any URL at all it's expanded to new URL("the path", "about:srcdoc") which obviously isn't a valid url.
Would it be possible to add a config option to specify the base parameter?
Like
urlBase?: undefined | string | "root"
where "root" would have the special meaning of using the root windows url.
Hey, as it's a niche usecase, I would recommend either:
- Adding a
htmx:configRequestevent listener in your JS to modify the request's URL throughevent.detail.path(just realized that this event's documentation doesn't mentionpaththough... But it's here!) - Creating a custom extension to handle that (that would use the same mechanism as described in my first point, this would simply allow you to configure it per-element with for example the said URL prefix in an attribute value)
Hope this helps!
Hey, yes it helped, thank you :) not sure if I should close this though, I can still see a use case for this 🤔
On Wed, Feb 26, 2025, 08:43 Vincent @.***> wrote:
Hey, as it's a niche usecase, I would recommend either:
- Adding a htmx:configRequest event https://htmx.org/events/#htmx:configRequest listener in your JS to modify the request's URL through event.detail.path (just realized that this event's documentation doesn't mention path though... But it's here https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js#L4367-L4384 !)
- Creating a custom extension to handle that (that would use the same mechanism as described in my first point, this would simply allow you to configure it per-element with for example the said URL prefix in an attribute value)
Hope this helps!
— Reply to this email directly, view it on GitHub https://github.com/bigskysoftware/htmx/issues/3212#issuecomment-2684179642, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACOHZTQUU2EBHZEHLGXTDZD2RVWBLAVCNFSM6AAAAABX2TPHCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBUGE3TSNRUGI . You are receiving this because you authored the thread.Message ID: @.***> [image: Telroshan]Telroshan left a comment (bigskysoftware/htmx#3212) https://github.com/bigskysoftware/htmx/issues/3212#issuecomment-2684179642
Hey, as it's a niche usecase, I would recommend either:
- Adding a htmx:configRequest event https://htmx.org/events/#htmx:configRequest listener in your JS to modify the request's URL through event.detail.path (just realized that this event's documentation doesn't mention path though... But it's here https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js#L4367-L4384 !)
- Creating a custom extension to handle that (that would use the same mechanism as described in my first point, this would simply allow you to configure it per-element with for example the said URL prefix in an attribute value)
Hope this helps!
— Reply to this email directly, view it on GitHub https://github.com/bigskysoftware/htmx/issues/3212#issuecomment-2684179642, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACOHZTQUU2EBHZEHLGXTDZD2RVWBLAVCNFSM6AAAAABX2TPHCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBUGE3TSNRUGI . You are receiving this because you authored the thread.Message ID: @.***>
the latest version 2.0.5 now has this:
const url = new URL(path, location.protocol !== 'about:' ? location.href : window.origin)
This hopefully handles about:srcdoc use cases