Internal UrlRequest intercept doesn’t work from a custom element?

Hi there!

I have a Browser.application setup with the usual code around UrlRequests: if there is an Internal URL request, the URL in the browser should change without executing a page load.

It works as expected, except with links that are part of the contents of a custom element I’m using. That custom element simply allows me to embed raw html (because it’s full of errors and parsing it presents some issues).

Any idea why that happens?

It’s because elm/virtual-dom adds a click listener to every <a> element that it creates. That click listener is what results in onUrlRequest rather than a browser standard page load.

You can see how that _VirtualDom_divertHrefToApp function is set up here:

If elm/virtual-dom instead had listened for the click event on the whole document and checked if the click came from inside an <a> element, your case should have just worked. Not sure if that approach could have downsides. But patching the JS output to try to achieve this might be a workaround (unless someone comes up with some easier idea).

Edit: It might be easier to use html-parser 2.4.0 to parse the raw HTML into elm/virtual-dom nodes and render those. Then you get the link click listeners for free.

Ah yes, I’d seen that there was an event there, thanks for explaining how all this works!

Yes parsing the HTML would work, but since my HTML is quite weird (invalid) I think it just doesn’t work with the parser you linked, and it works incorrectly with danneu/html-parser (see Parsing tables with missing `</td>` *and* `</tr>` is different than in browsers · Issue #5 · danneu/html-parser · GitHub).

I will have to fix that backend code eventually and produce “more valid” HTML anyway. Just postponing this to “later” once again! :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.