GoogleChrome / rendertron

A Headless Chrome rendering solution
https://render-tron.appspot.com/
Apache License 2.0
5.94k stars 808 forks source link

Can we add a functionality to strip Styles #440

Closed anishsrinivasan closed 4 years ago

anishsrinivasan commented 4 years ago

I faced an issue while rendering the web page using Facebook Scrapper, where my Vue setup meta tags are placed after inline styles. Because of Facebook Scrapper's timeout, Meta tags are not rendered. So I was checking renderer.ts, there I found a function to strip javascript of the rendered page.

There I added style, which resulted in style tags being stripped down by rendertron thus facebook was able to render my webpage properly.

function stripPage() {
  // Strip only script tags that contain JavaScript (either no type attribute or one that contains "javascript")
  const elements = document.querySelectorAll('script:not([type]), script[type*="javascript"], script[type="module"], link[rel=import], style');
  for (const e of Array.from(elements)) {
    e.remove();
  }
}

We can get extra params in config as

{
"cache": "memory",
    "cacheConfig": {
        "cacheDurationMinutes": 120,
        "cacheMaxEntries": 50
    },
 stripElements:['style'] // style, div
}

Let me know what you think, then I'll raise PR.

AVGP commented 4 years ago

This sounds like an issue specific to your page. For example: Would this be solved by making the meta tags appear above your inline styles instead of extending the codebase of Rendertron?

I'm not sure this use case is as broad as warranting the additional maintenance for this feature - plus for most bots we're recommending not stripping styles.

AVGP commented 4 years ago

Closing due to inactivity, feel free to reopen if needed.

anishsrinivasan commented 3 years ago

This sounds like an issue specific to your page. For example: Would this be solved by making the meta tags appear above your inline styles instead of extending the codebase of Rendertron?

I'm not sure this use case is as broad as warranting the additional maintenance for this feature - plus for most bots we're recommending not stripping styles.

Yeah, it has a small scope, but it would be useful in some cases. Btw, is there any reason why you're not recommending not stripping styles for bots?