BrowserSync / browser-sync

Keep multiple browsers & devices in sync when building websites. https://browsersync.io
https://discord.gg/2d2xUThp
Apache License 2.0
12.19k stars 757 forks source link

Feature Request: RewriteRules with dom manipulation instead of regexp #1025

Open kairos666 opened 8 years ago

kairos666 commented 8 years ago

First of all, BrowserSync is awesome :) Second, hopefully this feature is already feasible therefore it is a noob question.

problem

I proxy an external URL and need to modify HTML requests on the fly (I don't have access to this external HTML source). So at the end, on the browser, I should get a mix of the proxied HTML and my own.

RewriteRules gives me exactly this. problem solved! ... BUT ... working with regexp is really a pain. I need to select specific html tags and their content before rewriting them.

I would prefer an approach with a parsed DOM (jsdom, harmon/trumpet, ...) so that i can easily manipulate the HTML with jQuery like selectors. Unfortunately i couldn't find a recipe to do just that.

Any suggestions?

shakyShane commented 8 years ago

the next version will allow you to just provide a function that receives the entire document, and you return whatever you want from it. So then you could parse it using whatever tools you like.

kairos666 commented 8 years ago

I've made up a middleware that does just that with cheerio (jsDom + custom JQuery). Works fine but I've got some few caching issues.

It makes sense to have such a feature out of the bs box. Sounds great. Thanks.

linkurzweg commented 5 years ago

@shakyShane Is there a function to receive the entire document now? Couldn't find anything in the docs.