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 incorporate specific CSS files for Responsive Design for Desktop and Mobile Browsers

    How to have a textbox with label inside it support 'tap to paste' feature in iPad?

    How to fill margin space with divs and give it styles?

    How do I move this label inside my textarea?

    How to get Google menu buttons like styling using CSS

    How to make background color extend all the way to bottom of page / content?

    How can I override an external css?

    How to reuse a css background sprite for icons of different sizes?

    How to put all Array values in $_GET[]

    How to make links look like tabs using html/css?

    How to get anchor tag on background image of div?

    how to style php file with css + 1 more than one element

    jQuery - CSS DropDown Navigation Items - How to build a Carrot Dropdown

    how to ignore br or line breaks in text with pure css truncate text button

    How to write a more specific css

    How to automatically resize the wrapper div using CSS

    php search result images show across and fill a CSS div

    Django-Bower + Foundation 5 + SASS, How to configure?

    How to modify programmatically with javascript the css ::before and ::after [duplicate]

    How to keep layout unchanged when keyboard is displayed?

    how to avoid from loading unnecessary javascript and css in page on codeigniter to improve the load time [closed]

    How to center div and ul using CSS?

    How to highlight the menu item in menu

    how to change the color of disabled controls

    How to adjust width of right-aligned navbar

    jQuery: accordion-LIKE format. how to prevent div from collapsing if one of the checkboxes is checked

    how to make edges round in CSS?

    How to style Menu border/outline in JavaFX8 using CSS?

    How to make text input in table cell grow beyond the limits of the table when selected?

    How to move stacked columns up (using bootstrap but any css will do)