How to re-render a page from a Google Chrome extension?


Tags: javascript,css,google-chrome,google-chrome-extension

Problem :

I'm new to writing extensions for Google Chrome. I want to make an extension that only runs on a few pages (that I'll choose) and re-renders their CSS after the page has loaded (ideally I would like something similar to what you can do with GM_addStyle in greasemonkey scripts).

How can I accomplish this in a Chrome extension?



Solution :

You can use Content scripts that have access to the pages DOM.

In your manifest.json you could have:

"content_scripts": [
    {
      "matches": ["http://www.google.com/*"],
      "css": ["mystyles.css"],
      "run_at": "document_end"
    }
  ],

This will inject the css file mystyles in to any google page after the DOM has loaded. This doesn't completely overwrite the styles, but you will be able craft your CSS so it replaces their styles.

More information can be found on code.google.com. It also includes information about how to programmatically inject CSS into a page.


    CSS Howto..

    How to send HTML to an embedded WebView without running a local webserver?

    jQuery: How can I set css with own width?

    How to make css opacity property not to be inherited from parent div´s?

    Nested CSS: How to get to the child?

    how to inherit classes in css

    How to quickly create complex web controls for web development? [closed]

    ASP.NET: How to set the css class of a Control during DataBind?

    How do you apply a fading overlay to an image in CSS?

    How to use bootstrap to hide one of div when zoom browser windows size smaller

    How to position an element just off the top of the browser viewport using only css?

    how to restore to original CSS

    How to align icons in a form using flexbox / css in a responsive way

    how to specify different css for ie

    How to edit WordPress CSS written as inline CSS? [duplicate]

    How to make transition effect on css sprite hover

    How to delete space in css?

    How to use Bootstrap Glyphicons in Holder.js images

    How do I add a dropdown menu to my css menu?

    How can I use Modernizr to get border-radius working in IE8?

    How to add image and change visibility on hover CSS

    When using padding-top to retain aspect ratio for fluid layout, how do I vertically center text to background image?

    How not to display / filter out special characters? (CSS or Javascript)

    How to set transition from JavaScript while still inheriting style from CSS [closed]

    How to make an element have a 'hover' effect (CSS) while hovering another element using jQuery?

    How to Change CSS style of the same element that is NOT Hovered

    How to nest multiple css attributes inside another attribute

    How to CSS style a div to look like a GUI control box with a label?

    CSS: How to specify table's height such that a vertical scroll bar appears?

    how to solve IE6 box model problem without adding extra div and using Valid CSS?

    How can I make a filter like this? [closed]